ios - 无法转换 FBSDKGraphRequestHandler 类型的值

标签 ios swift facebook swift2

当我尝试使用 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()
                          }
                }
            }
        })

谢谢!

图片(点击图片放大)

/image/yzt6b.jpg

最佳答案

我希望您使用最新的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/

相关文章:

ios - GPUImageUIElement 叠加大小

ios - 如何将图像从 tableView 传输到另一个 imageViewController?

ios - 我怎样才能得到一个只在下一个 View 中计算的值?

ios - 我的 IOS 应用程序已被拒绝 - 数据存储指南 (2.23) 我有 2 个可能的嫌疑人

ios - 环球银行金融电信协会 : how to run a function even when user kills the app

iOS 应用内购买 : Auto-renewable subscriptions by own system user account

javascript - Facebook 页面插件 - 响应式

ios - 实际登录前Facebook "Not Logged In"错误

android - 使用图形 API 获取 Facebook 页面事件

ios - 测试飞行 2.0.0 : "MyApp" isn't compatible with this device