2

I'm building a Rails backend for an iOS app. The backend needs to interface with Facebook to grab and use each user's Facebook friends.

But the Facebook 'friends' request is returning empty.

I'm essentially making the following request:

curl https://graph.facebook.com/[FILTERED_USER_ID_FOR_APP]?fields=friends&access_token=[FILTERED]&debug=all

I've looked at a ton of StackOverflow posts about this (this one, and this one, and this one, and more), but haven't found an identical problem or a solution that fits.

I seem to have set permissions correctly. Both on the Rails app and when the user authenticates through the iPhone app, I've set user_friends to be one of the permissions, and, in fact, when someone registers now, it asks them to OK the user friends permission.

But when I actually request their friends, I get a response telling me that there are many friends, but not returning any of them. The below response is for a user who definitely has friends on the app.

{
  "data":[],
  "summary": {
    "total_count": 419 
  },
  "__debug__": {
    "messages": [
       { 
        "link": "https:\/\/developers.facebook.com\/docs\/apps\/versions\/", 
        "message": "No API version was specified. This request defaulted to version v2.7.","type":"warning"
       },        
       {
         "link": "https:\/\/developers.facebook.com\/docs\/apps\/changelog#v2_0",
         "message": "Only friends who installed this app are returned in API v2.0 and higher. total_count in summary represents the total number of friends, including those who haven't installed the app.",
         "type": "info"
       }
     ]
   }
 }

What's perplexing to me is that a) The App ID/User ID/Access Tokens seem right, because I can get basic profile info, and b) I do not get an error telling me that the request doesn't have the proper permissions. If I make a similar request without permissions on the explorer, it returns a relevant debug note:

  {
    "message": "The field 'friends' is only accessible on the User object after the user grants the 'user_friends' permission.",
    "type": "warning"
  }

If I make it with the right permissions in the explorer, it returns a list of friends (in the data array).

So it doesn't seem to be a permissions issue, but the request is returning an empty friends list. Any ideas?

Community
  • 1
  • 1
Sasha
  • 6,224
  • 10
  • 55
  • 102
  • 2
    You're sure you've accounted for this? http://stackoverflow.com/questions/23417356/facebook-graph-api-v2-0-me-friends-returns-empty-or-only-friends-who-also-u – Igy Nov 21 '16 at 21:11

1 Answers1

6

With Igy's help (pointed to this answer), I found the specific answer to my issue, which seems worth adding here.

The problem was that the new 2.0+ API version only returns friends:

  1. Who are on the app
  2. Who have agreed to the user_friends permissions themselves.

1 was all figured out, but because I'm still testing the app out, and nobody had yet accepted permissions, my test user was the only person who had accepted permissions. Nobody else had accepted user_friends, so nobody showed up as a friend of the test user. Getting a friend of the test user to add the permissions fixed the problem, adding that friend to the list of friends returned.

Community
  • 1
  • 1
Sasha
  • 6,224
  • 10
  • 55
  • 102