我一直在尝试使用此代码来获取我的 iOS 应用程序所需的用户信息,当我按下 func loginButton 时,我应该登录并获取用户名和电子邮件,
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
if( error != nil)
{
println(error.localizedDescription)
return
}
if let userToken = result.token{
//Get user acces token
let token:FBSDKAccessToken=result.token
println("Token = \(FBSDKAccessToken.currentAccessToken().tokenString)")
println("User ID = \(FBSDKAccessToken.currentAccessToken().userID)")
let protectedPage = self.storyboard?.instantiateViewControllerWithIdentifier("ProtectedPageViewController") as! ProtectedPageViewController
let protectedPageNav = UINavigationController(rootViewController: protectedPage)
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController = protectedPageNav
}
//Show user information
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
if ((error) != nil)
{
// Process error
println("Error: \(error)")
}
else
{
println("fetched user: \(result)")
let userEmail : NSString = result.valueForKey("email") as! NSString
println("User Email is: \(userEmail)")
let userName : NSString = result.valueForKey("name") as! NSString
println("User Name is: \(userName)")
}
})
}
有一条评论显示用户信息,它应该打印电子邮件和用户名,它打印名称但不打印电子邮件,我收到以下错误:FBSDKLog: 从 Graph API v2.4 开始,对 /me 的 GET 请求应该包含一个明确的“字段”参数,任何人都知道我做错了什么吗?谢谢你