I’m trying to get the profile image for a Facebook user using the Graph API in the Facebook SDK for iOS but the example code from the website does not work for me.
https://developers.facebook.com/docs/graph-api/reference/user/picture/
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"/123456789/picture"
parameters:nil
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
// Insert your code here
}];
I get the following error in the console.
FBSDKLog: starting with Graph API v2.4, GET requests for //123456789/picture should contain an explicit "fields" parameter
From my understanding of the error message instead of parameters:nil
I need to enter something like parameters:@{@"fields": @"id"}
but whatever I try result
in the completing handler is always nil. I don’t know what to enter for the profile picture.
EDIT:
I’m looking to get the profile picture for other users.
2
Answers
Try This One:-
You can use the following code for getting the data from the facebook login:-
-(void)getFacebookProfileInfos
{
FBSDKGraphRequest *requestMe = [[FBSDKGraphRequest alloc]initWithGraphPath:@”me” parameters:@{@”fields”: @”id,email,name,birthday,first_name,last_name,gender,picture.type(large)”}];
}
you will get all the data in the “dictUserData” dictionary and from that you will access the facebook profile in this way:-
UIImage * imgProfile = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@”%@”, dictUserData[@”picture”][@”data”][@”url”]]]]];
NSString * strImageData = [self imageToNSString:imgProfile];