Facebook GraphRequest for Swift 5 and Facebook SDK 5

半城伤御伤魂 提交于 2020-01-05 04:56:07

问题


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.

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.

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

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/


回答1:


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)


来源:https://stackoverflow.com/questions/56625462/facebook-graphrequest-for-swift-5-and-facebook-sdk-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!