简体   繁体   中英

Fetch User Profile Picture from new Facebook sdk 4 in ios

I am developing an App in Which I have implemented Facebook now I want to fetch Facebook user profile picture and Birthday in my app. I searched into net but all tutorials are 2 or 3 years old.

I have set permission like..

 loginButton.readPermissions=@[@"public_profile", @"email", @"user_friends",@"user_birthday",@"user_location"]; 

and fetching with codes

if ([FBSDKAccessToken currentAccessToken]) {
            [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
             startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                 if (!error) {
                     NSLog(@"fetched user:%@", result); 
} 

but the output is

  fetched user:{
email = "XYZ@gmail.com";
"first_name" = XYZ;
gender = male;
id = xxxxxxxxxxx;
"last_name" = ABC;
link = "https://www.facebook.com/app_scoped_user_id/xxxxxxxxx/";
locale = "en_GB";
name = "XYZ ABC";
timezone = "5.5";
"updated_time" = "2015-04-08T06:57:20+0000";
verified = 1;

}

Why i not getting birthday and profile picture information?

As Ashish mentioned, initWithGraphPath:@"me" parameters:nil does not return the profile_pic (or birthday) unless explicitly requested through initWithGraphPath:@"me" parameters:@{@"fields": @"picture, birthday"}

Be careful though, when parameters are not nil, it only returns the requested fields, so you won't get name, gender, etc unless you add them to the parameters explicitly as well

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM