1

I am trying to get a list of friends for my app, however this is what the console returns:

    {
    data =     (
    );
    summary =     {
        "total_count" = 1221;
    };

The total count is right but it doesn't show me any of my friends?

I have created two test users on the facebook developer portal and they have both logged in with my app, and they are friends with me on facebook, shouldn't their data be showing?

Here is my code for requesting the permissions and such, this class is called each time the user logs in.

@implementation UploadUser

NSString *userName;
NSString *userId;
NSString *userGender;
//UIImage *userPicture;
NSString *userPicture;

NSMutableURLRequest *urlRequest;

//NSData *imageData;
//NSData *pictureData;
//NSData *tempData;

//Retrieves users name, gender and id
-(void)getUserInfo {

    FBSDKGraphRequest *requestUser = [[FBSDKGraphRequest alloc]initWithGraphPath:@"me" parameters:nil];

    FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];

    [connection addRequest:requestUser completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
        userName = result[@"name"];
        userGender = result[@"gender"];
        userId = result[@"id"];

        if (connection) {

            if (!error) {

                [self setUserData];
                [self uploadUser];

            }
        }else if (!connection) {
            NSLog(@"Get User %@",error);
        }
    }];
    [connection start];


    //Get Friends
    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                  initWithGraphPath:@"/me/friends"
                                  parameters:nil
                                  HTTPMethod:@"GET"];
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                          id result,
                                          NSError *error) {
        if (connection) {
            NSLog(@"Friends = %@",result);


        }else if (!connection) {
              NSLog(@"Get Friends Error");
        }
    }];



}


//Saves user data to class
-(void)setUserData {
    DataManager *dm = [DataManager sharedInstance];
    [dm setObject:userName forKey:@"userName"];
    [dm setObject:userGender forKey:@"userGender"];
    [dm setObject:userId forKey:@"userId"];



    NSLog(@"%@",userId);
    NSLog(@"%@",userName);
    NSLog(@"%@",userGender);
}

//Uploads user data online
-(void)uploadUser {
    PFUser *user = [PFUser currentUser];
    user[@"name"] = userName;
    user[@"id"] = userId;
    user[@"gender"] = userGender;
    [user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            NSLog(@"User Data Uploaded :)");
        } else {
            //Handle Error
            NSLog(@"User Upload Error... %@",error);
        }
    }];
}

Why are isn't my query returning my friends? Is it because my friends are not authorised to use my app? Is my permissions not being asked properly?

D.Rosado
  • 5,634
  • 3
  • 36
  • 56
Josh
  • 745
  • 1
  • 7
  • 22

3 Answers3

1

Since v2.0 of the Graph API, you can only get the friends who authorized your App with user_friends too. This is subject of countless Stackoverflow threads already, for example: Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • I understand that, my problem is I logged in my friends and asked for `user_friends` permission? So shouldn't it be returning my friends since they are technically authorised. – Josh Jun 29 '15 at 08:16
1

Also you can use Graph API Explorer in order to quickly check if your request works: https://developers.facebook.com/tools/explorer/

If you want to check you friends you should ask your friend also use this link and get token. In this way the facebook system understand that your friend login in Graph API app and you will get the list of friends.

  • Hi, I got my "app's" current access token and the graph explorer returned. { "error": { "message": An active access token must be used to query information about the current user., "type": OAuthException, "code": 2500 } } Is this the error thats causing my issue? – Josh Jun 29 '15 at 08:39
  • @Josh Are you trying to click on button "Get Token" and then choose user_about_me and user_friend and click "Get access token". After this Facebook will ask you about permission and you should say "OK" and after this try to click "Submit" one more time. – Сергей Олейнич Jun 29 '15 at 08:44
  • When I do that, it just returns my "public_profile" and "user_about_me" info, not my friends list? – Josh Jun 29 '15 at 08:46
  • @Josh You should say one of your friends also go to this link and get access token. Only after this you will get list of friends. And there will be only one friend. – Сергей Олейнич Jun 29 '15 at 08:59
  • Right, but how will this solve my problem because I can't get every user to get an access token like this ? – Josh Jun 29 '15 at 09:09
  • @Josh I provide this link in order to test your Graph API request and see the real result that will be shown if you create the real app in app store. As luschn says now Facebook sdk doesn't have such function to return all your friends. It can return only the list of your friends that register using your app. – Сергей Олейнич Jun 29 '15 at 09:13
  • @Josh You can see this on this page https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids User IDs and Friends -> 3. /me/friends returns the user's friends who are also using your app – Сергей Олейнич Jun 29 '15 at 09:15
  • That is what I want, I want to get every user who has used my app hence the two test users? I still don't understand what I am doing wrong and why it is not working. – Josh Jun 29 '15 at 09:15
  • @Josh I think you should reqister both test user in your app and after this you should log as first tester and atfer this you will get list of your test user – Сергей Олейнич Jun 29 '15 at 10:28
  • @Josh I think you can try to add some of your friend as test user or developer for your app and if he register using your app you will get him as list of your friend – Сергей Олейнич Jun 29 '15 at 10:29
0

Check this one Get Facebook friends

Community
  • 1
  • 1
Pramuka Dias
  • 568
  • 4
  • 16