简体   繁体   English

Facebook iOS SDK用户配置文件登录属性

[英]Facebook iOS SDK User Profile Login Attributes

I've configured my project to use the Facebook SDK for logging in. I'm using the following frameworks: 我已经将我的项目配置为使用Facebook SDK登录。我正在使用以下框架:

FBSDKShareKit
FBSDKLoginKit
FBSDKCoreKit

I'm using this in a swift project so I've added the bridging header, imported all my frameworks to the header, and configured the property list properly with the application id after registering the project on facebook developer site. 我在一个快速的项目中使用了它,因此我添加了桥接头,将所有框架导入到头,并在Facebook开发者网站上注册该项目后,使用应用程序ID正确配置了属性列表。 I've also added in the necessary code in the AppDelegate methods. 我还在AppDelegate方法中添加了必要的代码。

My login code looks like this: 我的登录代码如下所示:

if(FBSDKAccessToken.currentAccessToken() != nil)   {
            returnUserData()
        }

        else{


            let loginView  = FBSDKLoginButton()
            loginView.center = view.center
            loginView.readPermissions = ["public_profile", "email", "user_friends"]
            loginView.delegate = self
            view.addSubview(loginView)
        }

    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
        if ((error) != nil){
            //Process error
            println(error.localizedDescription)
        }

        else if result.isCancelled{
            //Handle cancellations
        }

        else{

            println(result.token.description)
            //If you ask for multiple permissions you should check if
            //specific permissions are missings.
            if result.grantedPermissions.contains("email"){
                returnUserData()
            }
        }
    }

   func returnUserData (){

        let graphRequest  = FBSDKGraphRequest(graphPath: "me", parameters: nil)

        graphRequest.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
            if ((error) != nil)
            {
                // Process error
                println("Error: \(error)")
            }
            else
            {
                let id : String = result.valueForKey("id") as! String
                self.getUserProfileWithId(id)
                let userName : NSString = result.valueForKey("name") as! String
            }
        }
    }    

https://developers.facebook.com/docs/facebook-login/permissions/v2.4

The link above is the documentation I'm referring from for the permissions I should have. 上面的链接是我要获得的权限所参考的文档。 However, when I run the request, I only ever receive the "id" and "name" attributes from the call. 但是,当我运行请求时,我只会从调用中收到"id""name"属性。

The documentation states that the public_profile (default) should have 该文档指出public_profile(默认)应具有

*id
*name
*first_name
*last_name
*age_range
*link
*gender
*local
*timezone
*updated_time
*verified

However I never receive these attributes and I've confirmed that I have the granted permissions for public profile with this code. 但是,我从未收到这些属性,并且已经确认使用此代码具有对公共配置文件的授予权限。

 if result.grantedPermissions.contains("public_profile"){
                println("Permissions valid for profile")
            }

I've also changed the settings of my facebook account so that it is searchable and nothing is restricted but this seems to have no effect either. 我还更改了我的facebook帐户的设置,以便可以搜索并且没有任何限制,但这似乎也没有作用。 I tried on a friend's account and the result is the same, just the id and name fields are returned from the login call. 我尝试了一个朋友的帐户,结果是一样的,只是id和name字段是从登录调用返回的。 Any help on how to get the complete public_profile information would be awesome 关于如何获取完整的public_profile信息的任何帮助都将非常棒

With v2.4, you have to request each field you want to receive within the fields parameter's list: 使用v2.4,您必须在fields参数的列表中请求要接收的每个字段:

To try to improve performance on mobile networks, Nodes and Edges in v2.4 requires that you explicitly request the field(s) you need for your GET requests. 为了尝试改善移动网络上的性能,v2.4中的“节点和边缘”要求您显式请求GET请求所需的字段。 For example, GET /v2.4/me/feed no longer includes likes and comments by default, but GET /v2.4/me/feed?fields=comments,likes will return the data. 例如,默认情况下,GET /v2.4/me/feed不再包含喜欢和评论,但是GET /v2.4/me/feed?fields=comments,喜欢将返回数据。 For more details see the docs on how to request specific fields. 有关更多详细信息,请参阅有关如何请求特定字段的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM