swift 3 facebook sdk get friends list
Asked Answered
J

1

7

I need to get all my friends list:

I found this code:

var fbRequestFriends: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "/{friend-list-id}", parameters: [AnyHashable : Any]())

fbRequestFriends.start { (connection, result, error) in
    if error == nil && result != nil {
        print("Request Friends result : \(result!)")
    } else {
        print("Error \(error)")
    }
}

But in return I get this error:

Error Optional(Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSErrorFailingURLStringKey=(null)?access_token=EAAZAaT5Yj9qQBABsXA5KGpwvGX6wIdgX6h9mLtzz6YtgjiOB12XwWxl1MrDJLtZChWSOOKXDiizZCu7uZAixBmqP97HYUXkeg3lkTeeeyjmvhZBOZBibrp2Exa9uZB7V5fflJTvISF2aqK94H7E52svqei6SHvxi3W9vcynSI8hPQBBSawND9NHQif0wYIPuHIpbzl6ErBErvk6nm4ysMo1ZA0BFHVmflVYZD&format=json&include_headers=false&sdk=ios, NSErrorFailingURLKey=(null)?access_token=EAAZAaT5Yj9qQBABsXA5KGpwvGX6wIdgX6h9mLtzz6YtgjiOB12XwWxl1MrDJLtZChWSOOKXDiizZCu7uZAixBmqP97HYUXkeg3lkTeeeyjmvhZBOZBibrp2Exa9uZB7V5fflJTvISF2aqK94H7E52svqei6SHvxi3W9vcynSI8hPQBBSawND9NHQif0wYIPuHIpbzl6ErBErvk6nm4ysMo1ZA0BFHVmflVYZD&format=json&include_headers=false&sdk=ios, NSLocalizedDescription=unsupported URL, NSUnderlyingError=0x7a6285b0 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "unsupported URL" UserInfo={NSErrorFailingURLKey=(null)?access_token=EAAZAaT5Yj9qQBABsXA5KGpwvGX6wIdgX6h9mLtzz6YtgjiOB12XwWxl1MrDJLtZChWSOOKXDiizZCu7uZAixBmqP97HYUXkeg3lkTeeeyjmvhZBOZBibrp2Exa9uZB7V5fflJTvISF2aqK94H7E52svqei6SHvxi3W9vcynSI8hPQBBSawND9NHQif0wYIPuHIpbzl6ErBErvk6nm4ysMo1ZA0BFHVmflVYZD&format=json&include_headers=false&sdk=ios, NSErrorFailingURLStringKey=(null)?access_token=EAAZAaT5Yj9qQBABsXA5KGpwvGX6wIdgX6h9mLtzz6YtgjiOB12XwWxl1MrDJLtZChWSOOKXDiizZCu7uZAixBmqP97HYUXkeg3lkTeeeyjmvhZBOZBibrp2Exa9uZB7V5fflJTvISF2aqK94H7E52

Jannette answered 20/1, 2017 at 7:35 Comment(5)
What are you trying to do?Magniloquent
do you actually want to get the "friends" or the "friendlists"? there is a difference. btw, you can only get friends who authorized your app too and the api call is /me/friends.Expertism
/me/friendlists resp. /friendlist-id will only get you info about the list itself anyway (like the list name); it will not give you the users on those lists.Bandwidth
@luschn How does it know which friends have authorized the app?Carolynecarolynn
because those are the ones you get with /me/friends.Expertism
J
11

@CBroe is right, this is how the code should look like

let params = ["fields": "id, first_name, last_name, name, email, picture"]

let graphRequest = FBSDKGraphRequest(graphPath: "/me/friends", parameters: params)
let connection = FBSDKGraphRequestConnection()
connection.add(graphRequest, completionHandler: { (connection, result, error) in       
    if error == nil {
        if let userData = result as? [String:Any] {
            print(userData)
        }
    } else {
        print("Error Getting Friends \(error)");
    }

})

connection.start()
Jingo answered 20/1, 2017 at 9:41 Comment(8)
{ data = ( ); summary = { "total_count" = 235; }; } . not getting listMoseley
Bista please tell me why it is not giving the dataMoseley
What is the output? Any Error or message?Jingo
i found { data = ( ); summary = { "total_count" = 235; }; }Moseley
It only returns Facebook friends who have also signed up to your app, not the full list.Impress
@LukeStanyer how does it know which FB friends have signed up to the app?Carolynecarolynn
FB collects and keeps track of this automatically. Everybody that signs up to your apps gets added to a user list on FB servers and gets assigned a user id unique to your app that will never change.Impress
how to get friends list in iosRelator

© 2022 - 2024 — McMap. All rights reserved.