正如你已經與登錄部分完成,現在請在ViewDidAppear()
這個函數來獲取用戶信息:
func GetUserInfo(completionHandler handler: @escaping(_ response: [String: Any]) -> Void) {
if((FBSDKAccessToken.current()) != nil) { //If you have a valid Access token
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).start(completionHandler: { (connection, result, error) -> Void in
if (error == nil) {
//everything works fine print the user data
print(result ?? AnyObject.self)
//Here you can get any type of information of user
if let jsondata = result as? [String: Any], let strEmail = jsondata["email"] as? String, let fb_id = jsondata["id"] as? String, let picture = jsondata["picture"] as? [String: Any], let data = picture["data"] as? [String: Any],let url = data["url"] as? String {
print(url)
print(strEmail)
print(fb_id)
handler(jsondata) //Pass the data in the completion Handler
}
} else {
//failure popup
}
})
}
}
我認爲你必須創建一個函數並調用在ViewDidAppear函數() 。該功能將從facebook圖形API獲取用戶信息。 –
@AuuragSharma是的,它很清楚。但請告訴我們必須在ViewDidAppear中調用哪種方法?請發表一個答案,我一定會支持它。 –