简体   繁体   中英

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 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. 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 . You can take a look here:

Getting started - Facebook SDK for iOS

Here is an example of code in 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
}];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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