我想从Facebook获得用户生日。我可以得到姓名,电子邮件,身份但不是生日。
这是我的代码
loginButton = (LoginButton) findViewById(R.id.login_button_fb);
loginButton.setReadPermissions(Arrays.asList("public_profile, email, user_birthday"));
callbackManager=CallbackManager.Factory.create();
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
try {
String bday=graphResponse.getJSONObject().getString("birthday");
Log.i("Bdayyyyy---",bday);
} catch (JSONException e) {
e.printStackTrace();
}
Log.i("Login Activity", graphResponse.toString());
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender, birthday");
request.setParameters(parameters);
request.executeAsync();
答案 0 :(得分:1)
您需要获得生日许可,因为如果没有用户生日的扩展个人资料 权限,您将无法获得用户的生日。< / p>
LoginManager.getInstance().logInWithReadPermissions(Activity.this, Arrays.asList("public_profile", "user_birthday"));