如果用户ID来自已在您的应用程序中进行身份验证的用户,则可以使用图形API实现,就像Facebook文档上所说的那样:
“可以使用Facebook SDK和Graph API(https://developers.facebook.com/docs/graph-api)使用用户ID查询名称、照片和其他数据。这将仅包含已通过Facebook帐户登录您的应用程序的用户的ID。”
以下是如何使用用户ID调用图形API的一些代码:
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:[NSString stringWithFormat:@"/%@", {userID-goes-here}]
parameters:@{@"fields":@"name,id,picture,gender,birthday,email"}
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
if (!error){
NSLog(@"result: %@",result);
}
}];
这个请求的结果看起来像这样:
{
birthday = "06/24/1981";
email = "XXXXXX@hotmail.com";
gender = male;
id = 67XXXXX39;
name = "Adriano Spadoni";
picture = {
data = {
"is_silhouette" = 0;
url = "https://fbcdn-prof... ...jpg";
};
};
}
请记住,有些字段可能为空。
恐怕您需要逐个请求用户,如果有人知道如何同时询问一批用户,请告诉我们。
但是
如果您想从尚未安装您的应用程序的用户那里获取信息,则需要:
FBSDKGraphRequest(graphPath: "me/taggable_friends", parameters: ["fields":"installed,id,name,picture.width(1000)"]).startWithCompletionHandler({ (connection, result, err) -> Void in
if err == nil {
print(result)
}
})