I want to access the user birthday & gender, but I am getting an error when I try to access the birthday.I am using the Facebook SDK version facebook-android-sdk:4.18.0.
It gives me this error:
{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 100, errorType: OAuthException, errorMessage: (#100) Tried accessing nonexisting field (user_birthday) on node type (User)}}
Here is my code:
public class MainActivity extends AppCompatActivity {
private CallbackManager callbackManager;
private TextView info;
private LoginButton loginButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_main);
info = (TextView)findViewById(R.id.info);
loginButton = (LoginButton)findViewById(R.id.login_button);
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 object, GraphResponse response) {
Log.v("LoginActivity", response.toString());
// Application code
String email = object.optString("email");
String birthday = object.optString("birthday");
String name = object.optString("name"); // 01/31/1980 format
info.setText("email: " +
email + "\n" +
"birthday " + birthday+
"\n name"+name);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender,user_birthday");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
info.setText("Login attempt cancelled.");
}
@Override
public void onError(FacebookException e) {
info.setText("Login attempt failed.");
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
In the parameters you should use birthday instead of user-birthday:
parameters.putString("fields", "id, name, email, gender, birthday");
See the documentation for available fields of user bio: https://developers.facebook.com/docs/graph-api/reference/user/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With