无法在ios中获取用户个人资料照片

时间:2013-12-05 12:27:09

标签: ios iphone facebook facebook-graph-api slrequest

我想在ios中使用SLRequest来获取Facebook帐户详细信息。

我得到了所有细节但是无法获得用户的个人资料照片链接。

我的代码如下:

NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                         @"xxxxxxxxxxxxxx", ACFacebookAppIdKey,
                         [NSArray arrayWithObjects:@"email", nil] , ACFacebookPermissionsKey,
                         nil];

[_accountStore requestAccessToAccountsWithType:facebookTypeAccount
                                       options:options
                                    completion:^(BOOL granted, NSError *error) {
                                        if(granted){
                                            NSArray *accounts = [_accountStore accountsWithAccountType:facebookTypeAccount];
                                            _facebookAccount = [accounts lastObject];
                                            NSLog(@"Success");

                                            [self me];
                                        }else{
                                            // ouch
                                            NSLog(@"Fail");
                                            NSLog(@"Error: %@", error);
                                        }
                                    }];


- (void)me{
NSURL *meurl = [NSURL URLWithString:@"https://graph.facebook.com/me"];


    SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                              requestMethod:SLRequestMethodGET
                                                        URL:meurl
                                                 parameters:nil];

    merequest.account = _facebookAccount;

    [merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
        NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

        NSLog(@"%@", meDataString);

        NSJSONSerialization *js=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:nil];
        NSLog(@"%@",js);

    }];

}

帮我解决这个问题。

1 个答案:

答案 0 :(得分:2)

您可以从返回的回复中获取用户的ID,然后使用以下内容获取个人资料图片:

http://graph.facebook.com/User_ID/picture

我将SDWebImage用于图片:

NSString *urlstr = @"http://graph.facebook.com/100001393655684/picture";

[imageView setImageWithURL:[NSURL URLWithString:urlstr]
                   placeholderImage:nil];

对于Twitter,请确保您对请求进行身份验证,请查看this link以获取更多详细信息

注意:如果您没有为iOS5部署,则可能需要将TWRequest更新为SLRequest