Getting the “real” Facebook profile picture URL from graph API

后端 未结 12 2047
说谎
说谎 2020-12-12 15:25

Facebook graph API tells me I can get a profile picture of a user using

http://graph.facebook.com/517267866/picture?type=large

which works fine. However, whe

12条回答
  •  感动是毒
    2020-12-12 16:13

    For anyone else looking to get the profile pic in iOS:

    I just did this to get the user's Facebook pic:

    NSString *profilePicURL = [NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=large", fbUserID];
    

    where 'fbUserID' is the Facebook user's profile ID.

    This way I can always just call the url in profilePicURL to get the image, and I always get it, no problem. If you've already got the user ID, you don't need any API requests, just stick the ID into the url after facebook.com/.

    FYI to anyone looking who needs the fbUserID in iOS:

    if (FBSession.activeSession.isOpen) {
        [[FBRequest requestForMe] startWithCompletionHandler:
         ^(FBRequestConnection *connection,
           NSDictionary *user,
           NSError *error) {
             if (!error) {
                 self.userName = user.name;
                 self.fbUserID = user.id;
             }
         }];
    }
    

    You'll need an active FBSession for that to work (see Facebook's docs, and the "Scrumptious" example).

提交回复
热议问题