Reputation: 422
This is what i am doing to get user detail. I am able to get FbId,user name and usergender,I wants to get user birthdate too.please check below code Thanks in advance :-
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject user, GraphResponse response) {
// Application code
if (AccessToken.getCurrentAccessToken() != null) {
if (user != null) {
Log4Android.e(FaceBookLogin.this, user.toString());
// Log.e("onCompleted ", " 1= > " + new Gson().toJson(user));
facebookUser = new Gson().fromJson(user.toString(), FacebookUser.class);
try {
// Log.e("onCompleted ", " 2= > " + new Gson().toJson(user));
Log.e("onCompleted ", " 22= > " + new Gson().toJson(facebookUser));
if (facebookUser.getEmail() != null || !facebookUser.getEmail().equals("")) {
checkUserStatus(context, facebookUser.getId());
} else {
UtilitySingleton.getInstance(context).ShowToast(R.string.email_error);
}
} catch (Exception e) {
e.printStackTrace();
facebookUser = getUsableData(response);
UtilitySingleton.getInstance(context).ShowToast(R.string.email_error);
}
}
}
}
});
Bundle parameters = new Bundle();
// parameters.putString("fields", "id,name,email,first_name,last_name");
parameters.putString("fields", "id,name,email,gender,birthday,first_name,last_name");
request.setParameters(parameters);
request.executeAsync();
Upvotes: 0
Views: 902
Reputation: 304
In order to get the permission go to your facebook dashboard >App review > start a submission > and select user_birthday
You can do something along these lines of code -
if (AccessToken.getCurrentAccessToken() != null) {
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject user, GraphResponse response) {
if (response != null && response.getJSONObject() != null) {
try {
String birthDate = response.getJSONObject().getString("birthday");
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields","id,name,email,gender,birthday,first_name,last_name");
request.setParameters(parameters);
request.executeAsync();
}
And you should always check for access token before sending a GraphRequest.
Upvotes: 1
Reputation: 422
This solved my proplem:-
String BIRTHDATE = "user_birthday";
public static final String[] FACEBOOK_PERMISSIONS = {ValueKeys.PUBLIC_PROFILE, ValueKeys.EMAIL, BIRTHDATE};
LoginManager.getInstance().logInWithReadPermissions((Activity) context, Arrays.asList(FACEBOOK_PERMISSIONS));
Upvotes: 1
Reputation: 2879
What permissions are you asking for? getting the user birthday requires the permission: "user_birthday".
Upvotes: 1