获取iOS中其他Facebook用户的个人资料照片

时间:2018-02-05 00:31:14

标签: ios objective-c facebook facebook-graph-api

我试图使用Facebook SDK for iOS中的图谱API获取Facebook用户的个人资料图片,但该网站的示例代码对我不起作用。 https://developers.facebook.com/docs/graph-api/reference/user/picture/

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/123456789/picture"
           parameters:nil
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];

我在控制台中收到以下错误。

FBSDKLog: starting with Graph API v2.4, GET requests for //123456789/picture should contain an explicit "fields" parameter

根据我对错误消息的理解而不是parameters:nil,我需要输入类似parameters:@{@"fields": @"id"}的内容,但无论我在完成处理程序中尝试result,总是为零。我不知道要为个人资料图片输入什么内容。

修改 我正在寻找其他用户的个人资料照片。

2 个答案:

答案 0 :(得分:1)

试试这个:

$searchProducts

答案 1 :(得分:0)

您可以使用以下代码从facebook登录中获取数据: -

- (无效)getFacebookProfileInfos {     FBSDKGraphRequest * requestMe = [[FBSDKGraphRequest alloc] initWithGraphPath:@" me"参数:@ {@"字段":@" id,email,name,birthday,first_name,last_name,gender,picture.type(large)"}];

FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];

[connection addRequest:requestMe completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

    if(result)
    {
        dictUserData = [[NSDictionary alloc]init];
        dictUserData=result;
    }
}];
[connection start];

}

您将获得" dictUserData"中的所有数据。字典,您将以这种方式访问​​Facebook个人资料: -

UIImage * imgProfile = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",dictUserData [@" picture"] [@& #34;数据"] [@" URL"]]]]]; NSString * strImageData = [self imageToNSString:imgProfile];