12

I am creating an app and would like people using the app to find friends using the same app on Facebook. Any help on this would be great.

I know this can be done. I have seen it on Instagram and Tiger Woods 12.

iamsmug
  • 1,517
  • 4
  • 15
  • 25

3 Answers3

24

Once you've authorised the user and obtained an access token, you can quickly determine which of their friends have already authorised your app with a call to /me/friends?fields=installed

For the users' friends who have already authorised the app, the result will look like this:

{
   "installed": true, 
   "id": "{USER_ID_GOES_HERE}"
}, 

and for the users who have not already authorised the app, the result will look like this:

{
  "id": "{USER_ID_GOES_HERE}"
}, 

If you're doing this in the iOS SDK you won't see that exact return value, but the SDK should put the results into a data structure you can use, and check for the presence of the 'installed' item

You can also request additional User object fields other than just 'installed', but this is just a quick example to show you how to get the list of friends that use the app

Igy
  • 43,710
  • 8
  • 89
  • 115
  • Great, thanks for that. So when they authorise the app with facebook, i can put their fb id in my database so they can be followed etc in my app or is that not allowed. It's the only way I can think of marrying up the facebook users if my app with friends? – iamsmug Dec 12 '11 at 15:38
  • Well yes, you can store details in your own database and match users up that way, i'm not sure exactly what you're trying to do so I can't give an opinion as to whether it's policy compliant - many apps do have 'your facebook friends X,Y,Z already use this app, click here to add them as friends in the app' functionlity though – Igy Dec 12 '11 at 17:10
4

I have solved this problem in very easy way

Step 1= first download FbGraph API

Step 2= use this code for authentication

NSString *client_id = @"XXXXXXXXXXXXXX";// App id

//alloc and initalize our FbGraph instance
self.fbGraph = [[FbGraph alloc] initWithFbClientID:client_id];

//begin the authentication process.....
[fbGraph authenticateUserWithCallbackObject:self andSelector:@selector(fbGraphCallback:) 
                     andExtendedPermissions:@"user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins"];

Step 3= Copy fbGraphCallback: Method from sample code and put in your controller

Step 4= Use this code to get Friends and it will give u the list of friend and who have same app install They look like

{
   "installed": true, 
   "id": "{USER_ID_GOES_HERE}"
}, 

Code is =

NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];

[variables setObject:@"installed" forKey:@"fields"];

FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:@"me/friends" withGetVars:variables];

NSLog(@"getMeinstalled Friends:  %@", fb_graph_response.htmlResponse);

Thats it!!!!!!!!

Muhammad Rizwan
  • 3,470
  • 1
  • 27
  • 35
3

I know 'iphone' is tagged in the question, but still this answer might help others who will reach here:
The FQL query to get (just) the ids of all user's friends who are also users of the app is:

SELECT uid FROM user WHERE is_app_user=true AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
Yuval A.
  • 5,849
  • 11
  • 51
  • 63