Facebook Graph API 2.2 mutual friends

3.1k views Asked by At

So I've been trying for this for a couple of days, trying to figure out how to use Facebook's Graph API v2.2 to get mutual friends between two users. I understand that I can only get the mutual friends between two users that are using the FB App and that's cool.

The app has the following approved items:

  • email
  • public_profile
  • user_birthday
  • user_friends
  • user_hometown
  • user_location
  • user_relationships
  • user_website

My scenario is this:

  • A user (user A) register to the FB App
  • Another user (user B) registers
  • User A looks at the user B's profile
  • The profile should display the mutual friends between the two users

I've tried to play around in the Graph API Explorer

/v2.2/app_scoped_user_id?fields=context.fields%28mutual_friends%29
and
/v2.2/user_id?fields=context.fields%28mutual_friends%29.
These just returns an ID field with the ID I provided and nothing else.

I'm all out ideas, and the docs isn't helping much either. Can someone explain how to do it? I will be using it in an Angular app but as long as I can get the URL to fetch the correct thing I can translate it into Javascript.

1

There are 1 answers

2
Dylan Grafmyre On BEST ANSWER

For v2.3 - https://developers.facebook.com/docs/graph-api/reference/v2.3/user.context/mutual_friends

Between friends make sure the user_id in the query is the Facebook id of the other friend not the current user whose access token you are using.

GET /v2.3/{other_user.user-id}?fields=context.fields%28mutual_friends%29

For querying mutual friends between two non-friends you need to add a server appsecret_proof parameter plus the user access token.