Search code examples
iosfacebookios6

Getting user profile picture in iOS6?


I tried this:

meurl = [NSURL URLWithString:@"https://graph.facebook.com/me/picture"];
SLRequest *imageReq =[SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:meurl parameters:nil];
imageReq.account = self.facebookAccount;

[imageReq performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
    if (error) {
        NSLog(@"error -%@", [error debugDescription]);
    }else{
        NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

        NSLog(@"image -%@", meDataString);
    }


}];

But I get image - (nil).

I have an other request right above that code for user info and I get all the data just fine.


Solution

  • @shannoga - You are almost on the right path. Instead of me in your request, you have to use the Facebook user id. For that first make this request to get the user details - https://graph.facebook.com/me . Then from this request, get the user id in the handler from the json parsed response data. Using this user id, make this request - https://graph.facebook.com/userid/picture. In the response, you will get the response data which is your profile image data.