当我尝试使用 Facebook SDK 发出数据请求时收到以下错误:
无法将“(_,_,_) throws -> Void”类型的值转换为预期参数类型“FBSDKGraphRequestHandler!”
这是发生错误的相关代码。我在教程中找到了这个,但我认为它适用于旧版本的 XCode。我使用的是最新版本7.2.1。
已更新
let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, gender, email"])
graphRequest.startWithCompletionHandler ({ [weak self] connection, result, error in
if error != nil {
//onError()
print(error)
return
} else {
//get results
PFUser.currentUser()?["gender"] = result["gender"]
PFUser.currentUser()?["name"] = result["name"]
try PFUser.currentUser()?.save()
let userId = result["id"] as! String
let facebookProfilePictureUrl = "https://graph.facebook.com/" + userId + "/picture?type=large"
if let fbpicUrl = NSURL(string: facebookProfilePictureUrl) {
if let data = NSData(contentsOfURL: fbpicUrl) {
self.profilePic.image = UIImage(data: data)
let imageFile:PFFile = PFFile(data: data)!
PFUser.currentUser()?["image"] = imageFile
try PFUser.currentUser()?.save()
}
}
}
})
谢谢!
图片(点击图片放大)
最佳答案
我希望您使用最新的FBSDK
,因为completionHandler:
已更改。请参阅下面的代码:
let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: param)
graphRequest.startWithCompletionHandler { [weak self] connection, result, error in
if error != nil {
//onError()
print(error.description)
return
}else{
let fbResult = result as! Dictionary<String, AnyObject>
//Do You rest of the code here
}
})
关于ios - 无法转换 FBSDKGraphRequestHandler 类型的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35283212/