How to get Mutual Friends via Facebook's Graph API - facebook

Is there anyway to get a list of mutual friends using Facebook's Graph API?
I've been playing around with this tool and haven't yet figured out a way. However, I saw Simon's demo on Facebook's site, and it sounded like he was able to get the mutual likes of friend of his (it was too blurry to see how he did it so) so I feel like I ought to be able to, but I can't find any documentation besides some php scripts.

The Mutual Friends API was deprecated on April 4, 2018, and the endpoints below started returning empty data sets. The endpoints are now fully deprecated and will return an error. https://developers.facebook.com/docs/graph-api/changelog/version3.1#mutual-friends-api
You can use this one to get mutuals friends from the graph
https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Fmutualfriends%2F1207059

Goto the API Documentation page here:
http://developers.facebook.com/docs/reference/api/
Mid-way down the page you will see:
•Friends: https://graph.facebook.com/me/friends?access_token=...
You'll need to replace the /me/ with a valid ID of the person you are looking for and you;ll need to get the access_token as well.
Hope this starts you in the right direction..
EDIT: There is also this which may be easier:
http://developers.facebook.com/docs/reference/rest/friends.getMutualFriends/
Legacy REST method

I would do this as a FQL query and test it with their FQL tester. This might not be 100% what you are looking for, but it should be enough to get you started:
SELECT uid1, uid2 FROM friend
WHERE uid1 IN
(SELECT uid2 FROM friend WHERE uid1=me())
AND uid2 IN
(SELECT uid2 FROM friend WHERE uid1=me())
You could then look up these id's up against the user table.

Related

Facebook Graph API - Finding friends who like a page

I'd like to create a call to the Facebook Graph API to find friends who like a specific page.
In FQL it would be something like this:
SELECT uid FROM page_fan WHERE page_id=MYPAGEID AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
But this doesn't work as FQL is deprecated.
I can't seem to find a way to do this on the new version of the API.
Any suggestions? Iterating all fans of a page and compare them with the array of is not the best idea I guess? :-)
Thanks,
Koen
Facebook have locked down a lot of options for privacy, but the closest remaining endpoint might be Social Context
So, a call to graph.facebook.com/v2.4/{page_id}/?fields=context should show have a friends_who_like node, which would show you what you're looking for.

Facebook graph api search friends

Is there any way using the graph api to search all users but to list matching friends first?
If I search using this it requires a user access_token. So it knows who I am. So why does it (almost seem like its) avoiding displaying my friends? Why doesn't it return my friends that match the query first and then after that, anyone else?
Is there a way to make it mimic that functionality?
I also wondered the same thing as the OP. The only thing I've been able to come up with in my research is using FQL...The problem with FQL? After v 2.0 of the Facebook API it will no longer be available--and the version after that it will probably be deprecated.
But in the interest of getting a working solution NOW, I found this SO (third answer down): searching friends using facebook graph api
Here's the example that worked for me:
select uid, name, sex
from user
where uid in (SELECT uid2 FROM friend WHERE uid1 = me())
and (strpos(lower(name),'Jack')>=0 OR strpos(name,'Jack')>=0)
Also, if you want their pic use:
select uid, name, sex, pic_small
from user
where uid in (SELECT uid2 FROM friend WHERE uid1 = me())
and (strpos(lower(name),'Jack')>=0 OR strpos(name,'Jack')>=0)
(I'm getting their small pic but documentation for other sizes of the pic is found here: https://developers.facebook.com/docs/reference/fql/user/)

Graph API Explorer, returning different result

I am trying to FQL query comments, made by my on photo's my friends were tagged in.
SELECT text FROM comment WHERE object_id IN ( SELECT object_id FROM photo_tag WHERE
subject IN (SELECT uid1 FROM friend WHERE uid2 = me()) ) AND fromid=me() LIMIT 1000
The query in it self works fine on the Graph API Explorer. When i am on the Graph API Explorer, and then choose my app to run the query the result comes up empty, were the Graph API App returns results.
Any ideas on this? I have noted that other people have had this issue. But there seems to be no fix for it? I am wondering if people just gave up. Because i have also been at it for a while without any solutions.
I will limit the query, so it dosen't look back more than 3 months, but for now it's not so i am sure i get some data.
So, we found the issue ourselves, while the Graph API Explorer (the tool) follows the documentation that facebook provides, your own implementation does not. So it's consistently different, so we were able to make it work knowing this, so with what should actually be an bug we made it work.

Getting friends' facebook check-ins into a place

I'm trying to find which of my friends have been to Paris before. I'm trying to use the Graph API to do this.
So basically there's the place id (for Paris it's 110774245616525), I can get basic informations using the endpoint https://graph.facebook.com/110774245616525/ to do this. Then, I'm getting an access_token with friends_status and user_status permissions (using the Graph Explorer) and I'm using this access token to get the checkins. So I'm doing a GET https://graph.facebook.com/110774245616525/checkins?access_token=my_access_token call and all I get is this error message :
page_id is not a member of the checkin table
Although, reading the documentation I see the connection with checkins :
Checkins made to this Place Page by the current user, and friends of
the current user.
Is this an error with the Graph API or with the way I do it?
Thanks !
There's a breaking change for checkins in the July release https://developers.facebook.com/roadmap/ it mentions renaming page_id to target_id so this might be what's causing it. However the following fql query might be a starting point for you
select author_uid from checkin where target_id = 110774245616525
author_uid should be the person who checked in https://developers.facebook.com/docs/reference/fql/checkin
I got the following fql to work to display all the names of my friends who have checked in at a specific location. Only tried it in Graph API Explorer, and it was fairly slow :/ Let me know if it's helpful :)
Select name from user where uid in (Select author_uid from checkin where author_uid in (select uid2 from friend where uid1=me()) and target_id=110774245616525)
An additional note: I noticed that many of my friends show up in the "Friends who have visited Paris, France" box, but they don't have any actual checkins there. I think that the box also checks to see if your friends have any photos from paris.. Just a thought
With the help of asifrc and TommyBs I found a way to do this in FQL using this query :
SELECT name
FROM user
WHERE uid IN (
SELECT author_uid
FROM location_post
WHERE distance(latitude, longitude, "48.856614", "2.3522219") < 5000
AND author_uid IN (SELECT uid2 FROM friend WHERE uid1=me()))
It's pretty much getting all my friends, searching all their posts close to the center of Paris, then getting their names.
If anyone knows how to do this in Graph API, please let me know, because it's still not a good idea to rely on FQL, I think.

Facebook Graph API FQL returning less results than expected

I'm trying to get the pages that my friends like using this FQL multiquery:
{
"query1": "SELECT uid2 FROM friend WHERE uid1 = me()",
"query2": "SELECT uid, page_id, type FROM page_fan WHERE uid IN (SELECT uid2 FROM #query1)",
"query3": "SELECT page_id, name, categories, type, page_url, pic_big FROM page WHERE page_id IN (SELECT page_id FROM #query2)"
}​
The query works fine and returns results. However, it returns around 2940 pages for 260 people, which is way less than the sum of the actual like count for the people queried.
I considered it could be a permission problem and asked for one of the people on this list to remove "access likes, interests..." permissions for friends' applications. On the next run, her pages and likes weren't on the JSON returned, but the page count actually increased some 10 or 20 records.
Am I doing something wrong here? I'm using multiquery for performance reasons.
This occurs both using the Graph API explorer and the PHP SDK:
$fql = urlencode($fqlQuery);
$response = $facebook->api("/fql?q={$fql}");
Any thoughts on this problem?
Thanks in advance :)
There is an additional privacy feature on Facebook that might be limiting the results you receive from certain people.
The setting is in the privacy settings and its called - How people bring your info to apps they use
It also gives a short description -
People who can see your info can bring it with them when they use apps. Use this setting to control the categories of information people can bring with them.
One of the options within that settings is "Activities, interests, things I like". For my profile this option is set to off. So no matter what permissions an application gets from a friend of mine, that application will not be able to see my "Likes".
My suspicion is that some of your (wiser) users have this setting disabled as I do, and it is preventing your application from getting to that information.
As an aside, I think this setting is crucial for real privacy on a Social Network. Just because my friends can see what pages I like, doesn't mean I want any application they use to also be able to see that info.