简体   繁体   中英

iOS Facebook SDK Retrieve Friends List

I am trying to integrate Facebook iOS SDK and get a list of all the friends of the logged in user. I have already requested the permission to access the "user_friends" as shown below:

 login.logIn(withReadPermissions: ["public_profile","user_friends"], from: self) { 

And in my different view controller I try to fetch the friends list.

guard let request = FBSDKGraphRequest(graphPath: "/99999999923232321/friends", parameters: nil, httpMethod:"GET") else {
            fatalError("Unable to create the Facebook Request")
        }

        request.start(completionHandler: { (connection, result, error) in

            print(result)

        })

I get the error back:

▿ Optional<String>
  - some : "The operation couldn’t be completed. (com.facebook.sdk.core error 8.)"

You should create request with "me" parameter.And another thing,you should create empty parameter for just in case. Request should be like this:

let parametersForFriends = ["fields": "name,id"]
let graphRequestForFriends = FBSDKGraphRequest(graphPath: "me/friends", parameters: parametersForFriends)

EDIT

When you try to get friends like this,Facebook only return users friends only which is already login to your application. I mean if none of this user's friends login to your application,response will be empty.

Hope this help

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