My web app builds a batch request to the Facebook graph API. The batch is composed by making a first API call to grab the user's friends. Then I loop over the list of friends and add a specific request for each (with that user's specific access token) and add each one to the batch. So it ends up being two API calls. Unfortunately, it's REALLY slow, and I've heard the FQL requests are faster.
So my question is, can I do this with FQL? I've read the documentation but I can't figure out how I might return, for example, all the friends of friends' work history (which requires each friend's access token) with one single FQL query. Is this possible? Obviously I could build a batch request of FQL requests, but that would leave me back where I started.
UPDATE:
I've done some tests and FQL definitely seems to be faster than a batch request. My FQL multiquery looks like this:
$multiQuery = array(
"query1"=>"SELECT uid2 FROM friend WHERE uid1 = me()", //LIST OF FRIEND IDs
"query2"=>"SELECT uid, name, work, education, is_app_user FROM user WHERE uid IN (SELECT uid2 FROM #query1)", //FRIEND PROFILES
"query3"=>"SELECT uid2 FROM friend WHERE uid1 IN (SELECT uid FROM #query2 WHERE is_app_user=1)",
"query4"=>"SELECT uid, name, work, education FROM user WHERE uid IN (SELECT uid2 FROM #query3)"
);
$multiQueryResult = $facebook->api(array(
'method' => 'fql.multiquery',
'queries' => $multiQuery
));
var_dump( $multiQueryResult );
The query works but there are two problems:
query3 returns all the user ids, NOT just the ones who've authorized
my app.
query4 doesn't return the work/education fields... presumably
because the API request is being called with the current user's
access token (as opposed to that of specific user from query3). I've stored the authorized users' access tokens in the DB, but I don't know if it's possible to use them in this context.
CAN this be done with FQL?? Can I define unique access tokens within an FQL multiquery?
all the friends of friends' work history (which requires each friend's access token)
If you need different access tokens, then obviously there’s no way of doing it in one single request … but where would you get each of my friends access tokens anyway, if they wouldn’t have interacted with your app themselves recently? And if they would have, you could’ve gotten their work info then already and put it into your own database, so that you could get it from there just using the uids of my friends for lookup. Otherwise, I think this is not really your way to go.
It’d rather be this way:
If friends of your user have set up their privacy settings so that they are willing to share their work info with apps your user is using, then you can get that info without requiring an individual access token for each one of those friends. Then you would just do an FQL query like this,
SELECT uid, name, work FROM user WHERE uid IN
(SELECT uid1 FROM friend WHERE uid2 = me())
That’ll give you your user’s friends work info – but obviously only for those that are willing to share that info with apps a friend is using.
This isn't really an answer to my original question because there doesn't appear to be one. It seems that at the time of writing this, the Facebook batch request is just really slow... which is too bad since that basically defeats its entire purpose.
Related
So it seems FQL had a field on each user called mutual_friend_count. Is there any way to get this through the graph API?
I can get mutual friends, but I am trying to sort and cull the list when a user has below a certain number of mutual friends. Using 'mutualfriends' with the friends call takes forever and returns way too much data, I only need the count of each user, not a list of every friends mutual friend.
Am I going to have to resort to using FQL to grab this or am I missing something?
EDIT:
So it seems my best bet seems to be FQL - this gives me all my current users friends that have 200 friends in common, ordered by mutual friend count. My question is just whether this can be done directly via the Graph API.
SELECT uid, name, mutual_friend_count FROM user
WHERE uid IN (SELECT uid1 FROM friend WHERE uid2 = me())
AND mutual_friend_count > 200
ORDER BY mutual_friend_count DESC LIMIT 10
I have used a fql for get my friends information
SELECT uid,name,first_name,middle_name,last_name,pic_square,hometown_location,current_location,profile_url,email,website FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
it returning only friends id an name. Who have trusted my app there location also comming but when I am puting this fql on the Graph API Explorer
on facebook then it returns every one's location. Then How Can I get every one's location ?
It is hard to understand your question, though it looks like your app doesn't have all the required user permissions. The Graph API explorer, or the developer page are great resources to figure out which ones you need.
Hometown location,current location, email, and website are not "basic" data.
I'm tring to get my friends' birthdays in my app and some of them are null. I thought that those people don't have a birthday set, but they actually do.
My fql query is:
SELECT uid,name,birthday_date FROM user WHERE uid IN (SELECT uid2 from friend where uid1=me())
The birthdays are also null when I request /me/friends?fields=birthday
My access token has the friends_birthday permission set.
I also tried with birthday instead of birthday_date in the FQL query. Same result.
I imagine that this happens because they opted out somehow, but I don't know how.
Is there an alternate solution to actually get their birthdays from facebook?
It's also possible to remove the ability of apps to access your data when your friends use them, this option will prevent the current session user from seeing some information about their friends via the API, even if that information is accessible on Facebook.com
This setting is in the privacy settings, at https://www.facebook.com/settings/?tab=privacy, under Ads, Apps and Websites -> 'How people bring your info to apps they use' and looks like this:
{edit} you can test this for yourself with test users, it's the most likely reason assuming the birthdays are visible to you in the frontend
These people might have set their Birthdays visible to only themselves or only some restricted friends. This is an option available if we try to edit our Birthday by its side. That can cause it is not available to your query by app.
The Graph API makes it easy for me to determine who the friends of the current user are. I have two questions:
Is it possible, using the Graph API, to determine the list of users for the currently authenticated application?
Is it possible to determine the friends of the current user who are also users of my application (the intersection of my app's users and the current user's friends)? Is this possible using FQL?
No, This is not possible. Refer to this answer.
There's a rest method called friends.getAppUsers for this. Or you could use FQL:
SELECT uid,name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) AND is_app_user=1
I would like to get friends of friends via an API call and when I try to do it, I get the following exception,
{
"error": {
"type": "OAuthException",
"message": "(#604) Can't lookup all friends of .... Can only lookup for the logged in user (...), or friends of the logged in user with the appropriate permission"
}
}
The URL I am trying to access is,
https://graph.facebook.com/friend_id/friends?access_token=access_token
I am getting extended permissions which is as follows,
<fb:login-button perms="user_likes,friends_likes"></fb:login-button>
Could any one please let me know what's going wrong here? Or does it mean I can never get access to friends of friends?
Currently, there is no extended permission that allows you to view a user's friends of friends. The "*_likes" permissions just show you the Facebook pages that the users have Liked.
It might be possible for you to iteratively fetch and cache the friends of each of the user's friends, one by one, but without access tokens for each friend, you'll only be able to fetch public data.
I got friends of friends(limited). I had same problem. Though it is very late for answering question, it will help somebody. That's why answering this question.
We can get friends of friends those are app users.
$fb_id= user id whose friends of friends required.
$query="SELECT uid, name, work_history FROM user WHERE uid IN (SELECT
uid2 FROM friend WHERE uid1 IN (SELECT uid FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = $fb_id ) and is_app_user=1) )";
$user_info=$facebook->api(array('method'=>'fql.query',
'query'=>$query));
#Olie:
You are fetching your friends of your friend through application. So you would need permission from your friend whose friends you want. i.e. Your friend should be using that application and accepted those permission while allowing accessing information. Otherwise you wont be able to friends of your friend. I have tested this query. And it works successfully.
"message": "(#604) Can't lookup all friends of .... Can only lookup for the logged in user (...), or friends of the logged in user with the appropriate permission"
This message explains well. Read carefully.
Hope you understand solution criteria.
You cannot get friends of friends, it is not allowed due to privacy concerns.
A workaround we have done before is to save all users friends to oure own database.
That way we could cross-reference all the different users friend-list's and at least get friends of friends who have used the application we made.
Important note, such a table would quickly grow quite seizable depending on the amount of users you get.
Count on each user having about 250-300 friends on average, so if you opt for such a solution make sure to optimize your database for it, and then it should work just great.
Got same problem, had to use old REST API to get at least mutual friends, see
http://developers.facebook.com/docs/reference/rest/friends.getMutualFriends/
You can get the friends of the current user through a Graph API call to me/friends. You will need any valid access_token, no special extended permissions, just the Basic one. There is one caveat, that user must allow you to see their friend list. So in the Privacy Settings > Connecting on Facebook there is a "See your friend list" setting. If the user has chosen a custom setting and selected say "Only Me" you will get this error.
Similarly, if the current user allows others to see their friend list, but one of the friends shuts this down due to privacy concerns then you will not be able to see any data and will get that error.
I was able to verify the scenarios I have described.
Unfortunately, I can't ask your answer specifically since I don't have experience with the FB API. However, I believe that FB allows users to hide who their friends are. If they have this set, then perhaps you won't be able to access their friends at all. I'd try to modify your code to first check what the permissions of a given user are and only then accessing their friends list if you have access to it. A bit of speculation here, though.