Facebook Graph API mutual_friend_count? - facebook

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

Related

Get Facebook user friends sorted by relevance

Is there a way getting user friends list from Facebook as sorted on Facebook site?
For example when I tag someone in a picture, the friends offered by Facebook are sorted by relevance. Also the friends on the chat are sorted by relevance.
Is there a field which I can order by to achieve that or do I need to get parameters on each user and calculate some kind of friends ranking?
Theoretically you could use the mutual_friends_count field of the user table (https://developers.facebook.com/docs/reference/fql/user/) to do some kind of own sorting. You could query this via FQL:
SELECT uid,first_name, last_name,mutual_friend_count FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY mutual_friend_count DESC
But currently this is not working well: https://developers.facebook.com/bugs/242368225968716/

fql not working

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.

Convert Facebook API batch request into FQL multiquery

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.

How to get the count of FB friends my friends have?

Now my app is seeking the following permissions from user.
user_about_me,user_birthday,email, friends_about_me,friends_relationships
I'm getting the friends of the current logged in user and their relationship status. Is there any way to get the total count of FB friends for each one of them (i.e. No of FB friends my friends have) . I don't need the friends list but its enough to get the total no of FB friends a FB user have.
Is that possible? I know that if the user haven't authorized the app we couldn't find any information. But i guess the no of friends a FB user has may be a public data!!(unless he has privacy setting over them also)..
Is that possible using any FQL queries?
I have found a solution myself. Its possible to use the FQL to get the friends count.
There is a friend_count field against the user table.
SELECT uid, name, friend_count
FROM user
WHERE
uid IN
(SELECT uid2 FROM friend WHERE uid1=me())
The above query will retrieve all my friends with their names and their friend_count.

How to get friends in order of number of mutual friends?

I am developing a Facebook application. I want to know how I can get friends in the order of number of mutual friends.
Is it possible with FQL or any other method?
Update
I can't find a way to do it in one request using graph API
but it can be done in Ruby by getting friends list then sending request for each friend using User context like this example
Original answer
Here is the FQL query to be used Which is working only for api versions < v2.1
SELECT uid, mutual_friend_count from user where uid in (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY mutual_friend_count desc
you can try it in the explorer
https://developers.facebook.com/tools/explorer?method=GET&path=fql%3Fq%3DSELECT%20uid%2C%20mutual_friend_count%2C%20friend_count%20from%20user%20where%20uid%20in%20%28SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%3Dme%28%29%29%20ORDER%20BY%20mutual_friend_count%20desc
Theoretically, you can get a list of a user's friends using:
$friendsOfFriend = $facebook->api('/'.$yourFriendsFacebookId.'/friends');
Then you can check each of the result to see if they are your friend too.
$isMyFriend = $facebook->api('/me/friends/'.$someonesFacebookId);
... and keep a track of the count.
However my test didn't return any result yet. I attempted to get the friends of some of my facebook friends but it returns an exception: Can't lookup all friends of {friend's_facebook_ID}. Can only lookup for the logged in user {my_facebook_ID}, or friends of the logged in user with the appropriate permission. So there might be permission issue here.
I don't think mutual friends are available via FQL so you would have to do this the hard: calling the graph api in a loop for each friend and getting a count of mutual friends. The graph api method is: /me/mutualfriends/yourFriendsId and you could do 20 batch requests at a time to help speed this up. If you can find a way to do this with FQL, that would be your fastest route.
This is only a partial answer as they are not all in one place, still haven't found a way to get them on one page yet, but it is a start, could be run in a loop programmatically through your friend list...
https://www.facebook.com/browse/mutual_friends/?uid=xxxxxxxxxxxx
because if you don't give a uid it returns an error... I was just trying to get a list of all my friends on one pagem, but no dice. ridonculous.