Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift 3 facebook sdk get friends list

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

like image 712
Matrosov Oleksandr Avatar asked Jan 20 '17 07:01

Matrosov Oleksandr


1 Answers

@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()
like image 193
Bista Avatar answered Nov 14 '22 02:11

Bista