无法获得FB用户生日,android?

时间:2015-09-09 09:33:25

标签: android facebook

我正在尝试获取Facebook用户的个人资料信息,如姓名,电子邮件,生日和地点。我无法获得用户的生日。

callbackManager = CallbackManager.Factory.create();
    loginManager=LoginManager.getInstance();
    loginManager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            // App code
            accessToken = AccessToken.getCurrentAccessToken();
            getProfileInformationFacebook(accessToken);
            Log.e("login res", loginResult.toString());
        }

        @Override
        public void onCancel() {
            // App code
        }

        @Override
        public void onError(FacebookException exception) {
            // App code
        }
    });

阅读权限:

loginManager.logInWithReadPermissions(this,
                Arrays.asList("user_about_me", "user_birthday", "user_location", "email"));

图表API请求:

public void getProfileInformationFacebook(AccessToken accToken) {
    GraphRequest request = GraphRequest.newMeRequest(
            accToken,
            new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(
                        JSONObject object,
                        GraphResponse response) {
                    Log.e("object", object.toString());
                    String fbId = null;
                    String fbBirthday = null;
                    String fbLocation = null;
                    String fbEmail = null;
                    String fbName = null;

                    try {
                        fbId = object.getString("id");
                        fbEmail = object.getString("email");
                        fbName = object.getString("name");
                        fbBirthday = object.getString("birthday");
                        JSONObject jsonObject = object.getJSONObject("location");
                        fbLocation = jsonObject.getString("name");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    } 
                }
            });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,email,location,birthday");
    request.setParameters(parameters);
    request.executeAsync();

图表API响应:

{"id":"10153618779823958","email":"wishygupta@yahoo.com","name":"Wishy Gupta"}

这里缺少什么?

1 个答案:

答案 0 :(得分:6)

Facebook默认不提供用户生日。您必须使用扩展权限将您的应用提交给Facebook审核才能访问用户的生日。

见这里:

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