Question

I am using Facebook SDK 3.14 (the latest), everything was working fine. Then yesterday, it stopped showing the Friends list of the logged in user.

Here's when I click on logIn buttonL

- (IBAction)buttonClickHandler:(id)sender {
// get the app delegate so that we can access the session property
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

// this button's job is to flip-flop the session from open to closed
if (appDelegate.session.isOpen) {
    // if a user logs out explicitly, we delete any cached token information, and next
    // time they run the applicaiton they will be presented with log in UX again; most
    // users will simply close the app or switch away, without logging out; this will
    // cause the implicit cached-token login to occur on next launch of the application
    [appDelegate.session closeAndClearTokenInformation];

} else {
    if (appDelegate.session.state != FBSessionStateCreated) {
        // Create a new, logged out session.
        appDelegate.session = [[FBSession alloc] init];
    }

    // Attempt to open the session. If the session is not open, show the user the Facebook login UX

    // if the session isn't open, let's open it now and present the login UX to the user
    [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                     FBSessionState status,
                                                     NSError *error) {
        // and here we make sure to update our UX according to the new session state
        [self updateView];
    }];

}

}

And in the updateView method, I am calling the JSON of the Facebook graph request:

- (void)updateView {
// get the app delegate, so that we can reference the session property
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
if (appDelegate.session.isOpen) {
    // valid account UI is shown whenever the session is open

    selectedPageURL=[NSString stringWithFormat:@"https://graph.facebook.com/me/friends?access_token=%@&fields=name,id,picture,gender",
                     appDelegate.session.accessTokenData.accessToken];

    [self load_HTTPRequest:selectedPageURL];

    [FBSession setActiveSession:appDelegate.session];
    FBRequest *me = [FBRequest requestForMe];
    [me startWithCompletionHandler:^(FBRequestConnection *connection,
                                     id result,
                                     NSError *error) {
        NSDictionary<FBGraphUser> *my = (NSDictionary<FBGraphUser> *) result;

        self.name.text = my.name;
        [self.profile setImageWithURL:[NSURL URLWithString:[[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [my id]] stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]];
    }];

And in the AppDelegate, that's what I included:

    - (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    // attempt to extract a token from the url
    return [FBAppCall handleOpenURL:url
                  sourceApplication:sourceApplication
                        withSession:self.session];
}

These were doing good, but suddenly the friend list is empty (Empty Json), any advice?

Was it helpful?

Solution

I think it's because the last Facebook SDK only returns our friends which allow the app to access their profile information. Thus, our friend list will only return friends which allowed the App before the request.

As you can see below the permissions to access our friend list:

"Permissions

A user access token with user_friends permission is required to view the current person's friends. This will only return any friends who have used (via Facebook Login) the app making the request."

https://developers.facebook.com/docs/graph-api/reference/v2.0/user/friends/

OTHER TIPS

Even the Facebook android mobile App itself is showing the same error.

Seems like Facebook has a bug in their APIs .

  1. Goto Any person's profile.
  2. Click "Friends" link.
  3. You will get a new window showing "Get to know null's friend" .
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top