Getting user profile picture in iOS6?

2019-08-16 06:50发布

问题:

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.

回答1:

@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.



回答2:

You can get you picture using

https://graph.facebook.com/XXXXXX/picture

where XXXXXX is your id on FB.

To get your id you can use:

https://graph.facebook.com/me



回答3:

The picture is in your responseData variable

you can use this:

NSLog(@"image -%@", responseData);

to view the image hex values