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);
}
}
2
Answers
In the parameters you should use birthday instead of user-birthday:
See the documentation for available fields of user bio:
https://developers.facebook.com/docs/graph-api/reference/user/
Some Facebook integrations require approval before public usage.
Without this you will received an ERROR message like this:
Until reviewed and approved by Facebook, your app can use only the public user’s profile and email.
See next useful recommendations:
Next links will be helpful for it:
https://developers.facebook.com/docs/facebook-login/permissions#reference-user_birthday
https://developers.facebook.com/docs/facebook-login/review/how-to-submit