Reputation: 31
With older versions of the Facebook SDK for iOS, I could ask for me/picture or userId/picture to fetch profile pictures. I'm getting a null response when I try this with the latest SDK.
Any idea why, and what's the best alternative if the API has changed?
Thanks!
Upvotes: 0
Views: 1929
Reputation: 2287
I had the same problem, I guess the changed something.maybe they want the developers to download the picture in "regular" way.
In the hackbook facebook sample code that come with the new SDK they download the picture like regular picture and not through request object :
NSString * url = [NSStringstringWithFormat:@"https://graph.facebook.com/%@/picture",facebookObjectIdString];
NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
UIImage *downloadedImage = [UIImage imageWithData:data];
As you Can See, Just download the image from the URL like any image. You can also download with NSURLRequest and sendSynchronousRequest etc...
Interesting to know if this is bug in the new SDK or decision.
update: on some cases you want to add access_token parameter if the picture belong to some facebook object that restrict the access of downloading the picture (like some page's pictures).
Upvotes: 1
Reputation: 2060
Actually, you can still use [facebook requestWithGraphPath:@"me/picture?type=large" andDelegate:self];
But in -(void)request:(FBRequest *)request didLoad:(id)result
, instead of using the value in result
, get the image data of request.responseText
, which is NSMutableData and build your image from there.
Example:
-(void)request:(FBRequest *)request didLoad:(id)result {
NSLog(@"Got user avatar");
UIImage *profileAvatar = [UIImage imageWithData:request.responseText];
UIImageView *avatarImageView = [[UIImageView alloc] initWithImage:profileAvatar];
[self.view addSubview:avatarImageView];
}
Credits: https://stackoverflow.com/a/10528707/982913
Upvotes: 1