我正在开发 iOS 应用程序,我需要从 facebook 获取用户好友列表以及个人资料图片。但是我可以毫无问题地登录,但仍然需要这两条信息。这是我的代码:
@IBAction func loginFBAction(_ sender: UIButton) {
let fbLoginManager:FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.logIn(withReadPermissions: ["email"], from: self) { (result, error) in
if error != nil {
let fbLoginresult:FBSDKLoginManagerLoginResult = result!
if(fbLoginresult.grantedPermissions.contains("email"))
{
print(fbLoginresult)
self.getFBUserData()
fbLoginManager.logOut()
}
print("Process error")
}
else if (result?.isCancelled)! {
print("Cancelled")
}
else{
print("Logged in")
func getFBUserData() {
if((FBSDKAccessToken.current()) != nil){
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 print the user data
print(result as Any)
}})
}
}