iOS facebookSDK获取用户的完整详细信息

编程入门 行业动态 更新时间:2024-10-21 19:50:18
本文介绍了iOS facebookSDK获取用户的完整详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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获取用户的完整详细信息

本文发布于:2023-11-17 08:26:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609460.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:详细信息   完整   用户   iOS   facebookSDK

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!