Getting user profile picture in iOS6?

2019-08-16 06:58发布

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.

3条回答
做个烂人
2楼-- · 2019-08-16 07:29

The picture is in your responseData variable

you can use this:

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

to view the image hex values

查看更多
神经病院院长
3楼-- · 2019-08-16 07:40

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

查看更多
疯言疯语
4楼-- · 2019-08-16 07:53

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

查看更多
登录 后发表回答