用于Swift 5和Facebook SDK 5的Facebook GraphRequest [英] Facebook GraphRequest for Swift 5 and Facebook SDK 5

查看:69
本文介绍了用于Swift 5和Facebook SDK 5的Facebook GraphRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在项目中将所有pods和快捷语言更新为Swift 5,并收到了大量错误消息,这些错误消息已慢慢解决.

I recently updated all my pods and swift language to Swift 5 in my project and got a ton of error messages which I have slowly addressed.

但是,我为此感到苦恼,Facebook GraphRequest之前运行得非常好,尤其是此错误消息位于GraphRequestversion参数上.

I am however struggling with this one, the Facebook GraphRequest was working perfectly before, in particular this error message is on the version parameter of the GraphRequest.

如果我删除了version参数,则会出现此错误:

And if I remove the version parameter I then get this error:

func fetchFacebookAttributes(fetchFBAttrbComplete: @escaping (Bool, String) -> ()){


        let graphRequestConnection = GraphRequestConnection()

        let graphRequest = GraphRequest(graphPath: "me", parameters: ["fields": "id, email, name, picture.type(large), first_name, last_name, gender, birthday"], tokenString: AccessToken.current?.tokenString, version: .defaultVersion , httpMethod: .get)

        graphRequestConnection.add(graphRequest) { (httpResponse, result) in 

            switch result {

            case .success(response: let response)://handling .success response case

                guard let responseDictionary = response.dictionaryValue else { return }


                //parse response code here...


            case .failed(let error):

                print (error)
                fetchFBAttrbComplete(false, "")
                break

            }//end switch

        }//end graphRequestConnection

        graphRequestConnection.start()//start connection


    }//end func

我看过这个FB文档,该文档显示了如何使用它的示例,但是我仍在努力了解如何使用它?这是一个单独的文件吗?

I have come across this FB documentation that shows an example of how to use it, but I am struggling to understand how that is used also? is this meant to be a separate file?

https://developers.facebook.com/docs/swift/graph/

推荐答案

在Swift 5中尝试以下方法:

Try this for Swift 5:

let graphRequest = GraphRequest(graphPath: "me", parameters: ["fields": "id, email, name, picture.type(large)"], tokenString: AccessToken.current?.tokenString, version: Settings.defaultGraphAPIVersion, httpMethod: HTTPMethod.get)

这篇关于用于Swift 5和Facebook SDK 5的Facebook GraphRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆