【问题标题】:Can't able to fetch the User Profile photo in ios无法在 ios 中获取用户个人资料照片
【发布时间】:2013-12-05 21:32:30
【问题描述】:

我正在尝试在 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);

    }];

}

帮我解决这个问题。

【问题讨论】:

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


    【解决方案1】:

    您可以从返回的响应中获取用户的 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

    【讨论】:

    • 感谢您的回复!我已经尝试过了,但得到了空响应。
    • 您确定用户 ID 正确吗?请发布您使用的 ID
    • 嗯,它为我返回了一个带吉他的大象,可能你需要检查你的网络设置
    • 那为什么我得到空响应?
    • 好吧!!那太棒了!推特呢?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-06
    • 2016-04-08
    相关资源
    最近更新 更多