I am trying to implement a facebook graph request just as described on their developer´s doc page (https://developers.facebook.com/docs/swift/graph). Xcode 10.2.1, swift 5.
But I keep getting the following error:
Contextual closure type '(GraphRequestConnection?, Any?, Error?) -> Void' expects 3 arguments, but 2 were used in closure body
I have done a lot of research and tried to fill in several arguments but I simply cannot figure out what the missing third argument might be.
import FBSDKCoreKit
let connection = GraphRequestConnection()
connection.add(GraphRequest(graphPath: "/me")) { httpResponse, result in
switch result {
case .success(let response):
print ("Graph Request succeeded: \(resonse)")
case .failed (let error):
print ("Graph Request failed: \(error)")
}
}
connection.start()
Can someone help please?
I got the same behavior. I am not that experienced in Swift and the Facebook Graph API and I'm not sure if it is a good solution but, currently (until I find a better solution), for me works:
connection.add(GraphRequest(graphPath: "/me", parameters: ["fields":"email"])) { httpResponse, result, error in
if error != nil {
NSLog(error.debugDescription)
return
}
// Handle vars
if let result = result as? [String:String],
let email: String = result["email"],
let fbId: String = result["id"] {
// internal usage of the email
self.userService.loginWithFacebookMail(facebookMail: email)
}
}