我希望从Facebook和好友列表中获取用户ID,与朋友ID&个人资料图片朋友的网址。我有两个代码示例,首先是
NSDictionary *params = @{@"fields": @"name, id, picture"};
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/friends" parameters:params HTTPMethod:@"GET"];
这也会返回朋友的个人资料图片网址,但不会返回用户自己的Facebook ID。第二是
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"/me" parameters:@{@"fields": @"id,name,friends, picture"}]
这会返回用户的Facebook ID,朋友列表,但不会返回朋友的个人资料图片网址。你能帮我解决这个问题,我怎样才能在一次通话中得到这两件事?
答案 0 :(得分:2)
请使用以下代码段:
-(void)getFacebookFriednData{
FBSDKLoginManager *fbSdkLoginManager = [[FBSDKLoginManager alloc] init];
[fbSdkLoginManager logOut];
[fbSdkLoginManager logInWithReadPermissions:@[@"email",@"public_profile",@"user_friends"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (!error) {
if (!result.isCancelled) {
NSDictionary *params = @{@"fields":@"id,name,email,picture,friends"};
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"me"
parameters:params
HTTPMethod:@"GET"];
[SVProgressHUD show];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
[SVProgressHUD dismiss];
if (!error) {
NSLog(@"%@",result); // here u get all require data
}
}];
}
}else{
NSLog(@"%@",error.localizedDescription); ?/ Handle Error Here.
}
}];
}
答案 1 :(得分:1)
SWIFT 3
这是我为使用我的应用的朋友获取此信息的方式
if ((FBSDKAccessToken.current()) != nil){
if let request = FBSDKGraphRequest(graphPath: "me/friends", parameters: ["fields": "email, name, gender, picture"] ) {
request.start(completionHandler: { (connection, result, error) in
if (error == nil){
guard let userInfo = result as? [String: Any] else { return } //handle the error
print("data------:\(userInfo)")
} else {
//handle any errors
}
}
}
}
userInfo包含您需要的数据。
答案 2 :(得分:0)
您可以使用此代码:
NSString *pictureURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large&return_ssl_resources=1", facebookID];