Iam使用最后一个FBSDK(使用swift)
Iam using the last FBSDK (using swift)
//MARK: sign in with facebook func signInWithFacebook() { if (FBSDKAccessToken.currentAccessToken() != nil) { // User is already logged in, do work such as go to next view controller. println("already logged in ") self.returnUserData() return } var faceBookLoginManger = FBSDKLoginManager() faceBookLoginManger.logInWithReadPermissions(["public_profile", "email", "user_friends"], handler: { (result, error)-> Void in //result is FBSDKLoginManagerLoginResult if (error != nil) { println("error is \(error)") } if (result.isCancelled) { //handle cancelations } if result.grantedPermissions.contains("email") { self.returnUserData() } }) } func returnUserData() { 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("the access token is \(FBSDKAccessToken.currentAccessToken().tokenString)") var accessToken = FBSDKAccessToken.currentAccessToken().tokenString var userID = result.valueForKey("id") as! NSString var facebookProfileUrl = "graph.facebook/\(userID)/picture?type=large" println("fetched user: \(result)") }<当我打印获取的用户时,我只得到了id和名字! ,但是我要求获得电子邮件和朋友和个人资料的许可,出了什么问题?
when I print the fetched user I get only the id and the name ! , but i requested a permission for email and friends and profile , what's wrong ???
BTW:我从我的macbook中移动了这个项目到另一个macbook(因为我格式化了)它在我创建项目的macbook上工作得非常好,但在移动项目后(使用bitbucket clone)我得到了这个结果。
BTW : I moved this project from my macbook to another macbook ( because I formatted mine) it worked very well when it was at the the macbook which I created the project on , but after moving the project (using bitbucket clone) I got this results .
推荐答案根据新的Facebook SDK,您必须使用 FBSDKGraphRequest
As per the new Facebook SDK, you must have to pass the parameters with the FBSDKGraphRequest
if((FBSDKAccessToken.currentAccessToken()) != nil){ FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email"]).startWithCompletionHandler({ (connection, result, error) -> Void in if (error == nil){ println(result) } }) }文件链接: developers.facebook/docs/facebook-login/permissions/v2.4
用户对象参考: developers.facebook/docs/graph-api/reference/user
使用公开个人资料,您可以获得性别:
With public profile you can get gender :
public_profile (Default) Provides access to a subset of items that are part of a person's public profile. A person's public profile refers to the following properties on the user object by default: id name first_name last_name age_range link gender locale timezone updated_time verified更多推荐
iOS facebookSDK获取用户的完整详细信息
发布评论