简体   繁体   中英

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:

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. I've also added in the necessary code in the AppDelegate methods.

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.

The documentation states that the public_profile (default) should have

*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. 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. Any help on how to get the complete public_profile information would be awesome

With v2.4, you have to request each field you want to receive within the fields parameter's list:

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. 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. For more details see the docs on how to request specific fields.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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