简体   繁体   中英

Getting wrong mutual friends count from facebook

I am trying to get mutual friends from facebook but it is giving me wrong result. The total number of mutual friends count which I am getting is right but when the data is users is not coming

Request

https://graph.facebook.com/v2.8/1744744292507346?fields=context.fields(mutual_friends{name,picture.type(large)})&access_token=access_token

Response

{
   "context": {
      "mutual_friends": {
         "data": [
            {
               "name": "Gaurav Varshney",
               "picture": {
                  "data": {
                     "is_silhouette": false,
                     "url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/15541198_1872071033026134_3669335060573505093_n.jpg?oh=d4a95ee6cdb8d401be06e8f10fbf6d50&oe=59B0C911"
                  }
               },
               "id": "1919297771636793"
            }
         ],
         "paging": {
            "cursors": {
               "before": "MTkxOTI5Nzc3MTYzNjc5MwZDZD",
               "after": "MTkxOTI5Nzc3MTYzNjc5MwZDZD"
            }
         },
         "summary": {
            "total_count": 2
         }
      },
      "id": "dXNlcl9jb250ZAXh0OgGQHYKW1ALzRNZBAkUhMk2uDFtLZBBkzlasCZAq98zEqnPZBjqy7beHZBJZCVZB7STTw6yMnKC0w4qDA05ZBOGQ3RdRoPjfi1cbAmnChBQ1xLYpJuuKrIEZD"
   },
   "id": "1744744292507346"
}

I am only getting 1 friend since total_count is showing 2 .Can anyone tell me where I am doing wrong?And how can I use paging ??

When try to hit all_mutual_friends

https://graph.facebook.com/v2.8/1744744292507346?fields=context.fields(all_mutual_friends{name,picture.type(large)})&access_token=access_token

{
   "error": {
      "message": "(#10) To use all_mutual_friends on behalf of people who are not admins, developers and testers of your app, your use of this endpoint must be reviewed and approved by Facebook. To submit this feature for review please read our documentation on reviewable features: https://developers.facebook.com/docs/apps/review",
      "type": "OAuthException",
      "code": 10,
      "fbtrace_id": "HF3ZO8U3eLW"
   }
}

There is a lack of documentation about this feature and I had to dig about it. Mainly regarding on how to request that with Graph API.

That's how I'm doing and it is working, with some flaws that I will explain later:

Let's say we have here UserA and UserB. You need to collect the context-id of each of the user and save it on the server side because it must be used later on.

So, UserA connects and want to request mutual friends with UserB which is already connected. What you will need to do is:

UserA FB Graph request using this:

/'{{UserB context-id}}/all_mutual_friends?limit=5000', 'get'

also sending UserA fbaccesstoken

I use the limit 5000 to avoid pagination on the data results.

Now, the flaws:

The all_mutual_friends is giving me some headaches. I may be completely wrong, of course, but I debugged it for days and it seems there are some issues with Facebook when the feature is still in development mode and not public/authorized by FB. Don't know, I need to ask for permission to see that in production.

On my application I realised there are sometimes some mutual_friends are not actually listed and it is not a fault of the script, but probably some users configuration that avoid using this or some facebook problem. IDN.

Anyways, that's the way you should request mutual friends.

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM