2

I want to find out mutual friends between two random users using the facebook Graph API v2.2.

I read through the documentation https://developers.facebook.com/docs/graph-api/reference/v2.2/user.context/mutual_friends It says, "A valid user access token with user_friends permission is required to view the mutual friends of other friends using the app. "

Is there a way that I can find number and possibly names of all mutual friends between currentUser and User2, if they are not friends with each other?

I referred to many other questions: Facebook Graph API 2.2 mutual friends => No answers

How to get Mutual Friends via Facebook's Graph API => The solution works only if the two users are friends, which may not be true in my case.

Community
  • 1
  • 1
Manas Paldhe
  • 766
  • 1
  • 10
  • 32
  • They API works even if the 2 users are not friends. But both needs to grant user_friends permission – WizKid Feb 27 '15 at 07:12
  • No. I have the code ready. If user A and User B are friends- I get response, which has context and all the data I need. The response looks like this: response: Object context: Object mutual_friends: Object data: Array[some length] summary: Object id: "someId" link: "someLink" If User A and User B are not friends, response looks like this: response: Object id: "something" link: "somelink" Yes I am using link too, but removing that does not make any difference. – Manas Paldhe Feb 27 '15 at 07:21
  • Do they have any mutual friends that are using the app? – WizKid Feb 27 '15 at 07:23
  • Yes, they do. I just went and checked the FB account settings as well. The settings/apps/permissions for all three users shows that friend list is allowed to be accessed by the app. – Manas Paldhe Feb 27 '15 at 07:29
  • 1
    Just want to make sure I understand. You have user A, B, C and A is friend with B and B is friend with C. All three have logged in to your app and granted user_friends permission. And when you ask for mutual friends between A and C you don't get any? If so file a bug at https://developers.facebook.com/bugs – WizKid Feb 27 '15 at 07:46
  • Yes the above is correct. Is that not expected behaviour? The API says ""A valid user access token with user_friends permission is required to view the mutual friends of **other friends** using the app. "" – Manas Paldhe Feb 27 '15 at 07:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/71857/discussion-between-manas-paldhe-and-wizkid). – Manas Paldhe Feb 27 '15 at 08:48

5 Answers5

1

I am about to implement this myself. I have a similar use case where the two users may not be friends but I'd like to see which of their friends are mutual.

Apparently, you have to include an 'app proof' parameter with the API request from your server when the two users are not mutual friends:

If you want to call this endpoint on behalf two app-users who are not friends, then you must provide the appsecret_proof parameter along with the user access token when making the request. This means you must call this endpoint from your server.

Looks like this might be a good idea to do anyway.

Community
  • 1
  • 1
Chad Pavliska
  • 1,233
  • 12
  • 17
1

Managed to find a solution and it's working. If you got the call working within you and somebody else and you both are friends on Facebook, what you need to do is create the Appsecret

which represents the App secret key found on Facebook Dev under My Apps and the token. You create this key by running : $appsecret_proof= hash_hmac('sha256', $access_token, $app_secret);

Afterwards you pass the token and the secret as parameters to the call:

Bundle params = new Bundle(); 
params.putString("appsecret_proof", appsecret_proof); 
params.putString("access_token", access_token);
Alex
  • 108
  • 1
  • 11
  • I think it works only when "somebody else and you both are friends on Facebook". If you both are not, it does not. – Manas Paldhe Jul 22 '15 at 18:45
  • It does, and like I mentioned, it was tested. Let's assume me and you are not Facebook friends. I can get our mutual Facebook friends if given the permission. – Alex Jul 23 '15 at 08:46
  • Hi there, how did you implement this? do i need to run this on my server? my server uses a java application and not php so how would i implement this? – Lucas Senechal Aug 09 '16 at 20:18
1

It is working for 2 users who are not friends.

Here is a working example for facebook mutual friend API:

curl -G -d "access_token=<access_token>" -d "appsecret_proof=<appsecret_proof>" 'https://graph.facebook.com/v2.5/{user-id}?fields=context.fields(mutual_friends)'

The App secret proof is sha256 of user access token with app secret as the key.

Remember both user should be using your App. The response will have users who are also using your app and given friend list permission.

If you want to find specific info about the mutual friends try this:

curl -G -d "access_token=<access_token>" -d "appsecret_proof=<appsecret_proof>" 'https://graph.facebook.com/v2.5/{user-id}?fields=context.fields(mutual_friends.fields(id,name,picture.type(large)))'

This will return id, Name and current profile image link for all mutual friends. You don't need photos permission for this picture.

Shobhit
  • 11
  • 4
0

Facebook API does not allow this feature: https://developers.facebook.com/bugs/346462608889036/

Manas Paldhe
  • 766
  • 1
  • 10
  • 32
0

It's an old question but now I've dealt with it so I'll write...

to get all mutual friends if you not his friend it's passible only from a server(in my case it's Node) as mention here: https://developers.facebook.com/docs/graph-api/reference/user-context/all_mutual_friends/

get the token of user-2 and YOUR auth-id, also generate appsecretProof and clientSecret from your Facebook admin panel of your app.

https://graph.facebook.com/v2.10/${auth_userId}? 
fields=context.fields%28all_mutual_friends.limit%28100%29%29 
&appsecret_proof=${appsecretProof}&access_token=${accessToken}

remember to ask permmision from users when they login and also send app review to Facebook to approve this feature.

with 'user_friends' permissions you can get from client only mutual friends that use in your app but not all mutual friends.

Shmulik
  • 134
  • 2
  • 10