简体   繁体   English

可以在iOS中使用最新的SDK在应用程序中获取Facebook朋友列表

[英]Its possible to get Facebook friends list in app with latest SDK in IOS

我正在尝试将好友列表从Facebook转移到我的应用程序。可能在新版SDK中表示感谢。

With Facebook SDK 4.0 onwards, you will get your total facebook friends count and the list of facebook friends who are using the same app. 从Facebook SDK 4.0开始,您将获得您的Facebook朋友总数以及使用同一应用程序的Facebook朋友列表。 Facebook has restricted this usage, you can use "user_friends" permission to retrieve the list but can have only those friends who are using app created by you. Facebook限制了此用法,您可以使用“ user_friends”权限来检索列表,但只有那些正在使用由您创建的应用程序的朋友。 So, no full list access to anyone from now. 因此,从现在开始,没有任何人的完整列表访问权限。

Swift version: 迅捷版:

var fbRequest = FBSDKGraphRequest(graphPath:"/me/friends", parameters: nil);
fbRequest.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result : AnyObject!, error : NSError!) -> Void in

    if error == nil {

        println("Friends are : \(result)")

    } else {

        println("Error Getting Friends \(error)");

    }
}

Note: this only gets you the friends who also use the same app! 注意:这只会让您也使用同一应用程序的朋友们!

thanks to everyone.my working answer is here 谢谢大家。我的工作答案在这里

      FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
     [login logInWithReadPermissions:@[@"email"]   handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
         {
     if (error)
     {
         // Process error
     }
     else if (result.isCancelled)
     {
         // Handle cancellations
     }
     else
     {
         if ([result.grantedPermissions containsObject:@"email"])
         {
             NSLog(@"result is:%@",result);
                      if ([FBSDKAccessToken currentAccessToken])
                   {
                 NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);

                 [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists"}]
                  startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                      if (!error)
                      {
                          NSLog(@"resultis:%@",result);
                      }
                      else
                      {
                          NSLog(@"Error %@",error);
                      }
                  }];

             }
             //[login logOut];
         }
     }
 }];

Yes it is. 是的。 You need to use Facebook SDK and it's graph API . 您需要使用Facebook SDK及其graph API You can take a look here: 您可以在这里看看:

Getting started - Facebook SDK for iOS 入门-适用于iOS的Facebook SDK

Here is an example of code in Objective-C: 这是Objective-C中的代码示例:

// For more complex open graph stories, use `FBSDKShareAPI`
// with `FBSDKShareOpenGraphContent`
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{friendlist-id}"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM