获取Facebook用户的生日和电话号码

时间:2016-03-25 09:53:07

标签: ios swift facebook

 let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
        fbLoginManager.logInWithReadPermissions(["email"], fromViewController: self) { (result, error) -> Void in
            if (error == nil){

                let fbloginresult : FBSDKLoginManagerLoginResult = result
                if (fbloginresult.grantedPermissions != nil){

                    if(fbloginresult.grantedPermissions.contains("email"))
                    {
                        self.getFBUserData()
                    }
                }

            }

func getFBUserData(){
        if((FBSDKAccessToken.currentAccessToken()) != nil){
            FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email, gender, user_birthday, phone"]).startWithCompletionHandler({ (connection, result, error) -> Void in
                if (error == nil){
                    //everything works print the user data
                    print(result)
                }
            })
        }
    }

我正在尝试获取Facebook用户个人资料详情。 我尝试访问它时,我没有收到生日日期和电话 如何更改我的代码以获取用户的生日日期。 任何帮助将不胜感激。谢谢提前

3 个答案:

答案 0 :(得分:4)

在您的代码中进行此更改

func getFBUserData(){
        if((FBSDKAccessToken.currentAccessToken()) != nil){
            FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email, gender, birthday, phone"]).startWithCompletionHandler({ (connection, result, error) -> Void in
                if (error == nil){
                    //everything works print the user data
                    print(result)
                }
            })
        }
    }

并在Permissions数组中添加 的 @ “user_birthday”

答案 1 :(得分:3)

Facebook提供3个权限emailuser_friendspublic_profile,因为您不需要将您的应用置于Facebook审核中。仍然需要将您的应用程序放在developer.facebook.com上进行审核

以下是关于许可的全部内容:

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

Facebook明确表示:

enter image description here

答案 2 :(得分:1)

let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
        fbLoginManager.logInWithReadPermissions(["email"], fromViewController: self) { (result, error) -> Void in
            if (error == nil){

                let fbloginresult : FBSDKLoginManagerLoginResult = result
                if (fbloginresult.grantedPermissions != nil){

                    if(fbloginresult.grantedPermissions.contains("email"))
                    {
                        self.getFBUserData()
                    }
                }

@23/10/2002