Android-simple-facebook lib,获取用户生日日期

时间:2014-06-03 21:47:43

标签: android facebook facebook-graph-api android-simple-facebook

The question in github

我使用android-simple-facebook lib在facebook上登录并获取一些用户数据。

在这种情况下,我遇到的问题是我无法获得用户的生日数据。

我已将权限设置为SimpleFacebookConfiguration对象

private Permission[] permissions = new Permission[]{
Permission.EMAIL,
Permission.USER_BIRTHDAY,
Permission.PUBLIC_PROFILE,
Permission.PUBLISH_ACTION
};

以及此个人资料获取数据的权限

Profile.Properties properties = new Profile.Properties.Builder()
.add(Profile.Properties.ID)
.add(Profile.Properties.FIRST_NAME)
.add(Profile.Properties.LAST_NAME)
.add(Profile.Properties.BIRTHDAY)
.add(Profile.Properties.AGE_RANGE)
.add(Profile.Properties.EMAIL)
.add(Profile.Properties.GENDER)
.build();

但我无法从中获取数据。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

申请新的许可

 private Permission[] permissions = new Permission[]{
    Permission.EMAIL,
    Permission.USER_BIRTHDAY,

    };

     SimpleFacebook.getInstance().requestNewPermissions(permissions, new OnNewPermissionsListener() {

                @Override
                public void onFail(String reason) {
                    //mResult.setText(reason);
                    System.out.println(""+reason);
                }

                @Override
                public void onException(Throwable throwable) {
                   // mResult.setText(throwable.getMessage());
                    System.out.println(""+throwable.getMessage());
                }

                @Override
                public void onCancel() {
                }

                @Override
                public void onSuccess(String accessToken, List<Permission> acceptedPermissions, List<Permission> declinedPermissions) {
                    //   showGrantedPermissions();
                    mSimpleFacebook.getProfile(properties, onProfileListener);
                    if (declinedPermissions != null && declinedPermissions.size() > 0) {
                        Toast.makeText(LoginActivity.this, "User declined few permissions: " + declinedPermissions.toString(),      Toast.LENGTH_SHORT).show();


                    }
                }

            });

Profile.Properties properties = new Profile.Properties.Builder()
.add(Profile.Properties.ID)
.add(Profile.Properties.FIRST_NAME)
.add(Profile.Properties.LAST_NAME)
.add(Profile.Properties.BIRTHDAY)
.add(Profile.Properties.AGE_RANGE)
.add(Profile.Properties.EMAIL)
.add(Profile.Properties.GENDER)
.build();