Getting user profile picture in iOS6?

心不动则不痛 提交于 2020-01-16 08:35:28

问题


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



来源:https://stackoverflow.com/questions/14583030/getting-user-profile-picture-in-ios6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!