I am Trying to get gender and birthday of current login user from Facebook, but I always getting (id, email, name) I have search everything related to this but I didn't get exactly that for I am looking. below code, I have Trying that's not working.
facebookLoginButton = (LoginButton)view .findViewById(R.id.fragment_login_facebook);
facebookLoginButton.setFragment(this);
callbackManager = CallbackManager.Factory.create();
facebookLoginButton.setReadPermissions(Arrays.asList("public_profile", "email", "user_birthday", "user_friends"));
callbackManager = CallbackManager.Factory.create();
facebookLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
private ProfileTracker mProfileTracker;
@Override
public void onSuccess(LoginResult loginResult) {
String accessTocken = loginResult.getAccessToken().getToken().toString();
Log.v("TAG", "Access Token " + loginResult.getAccessToken().getToken());
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
try {
String email = object.getString("birthday");
String name = object.getString("gender");
Toast.makeText(getActivity().getApplicationContext(),email + " " + name ,Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender,birthday");
request.setParameters(parameters);
request.executeAsync();
if (com.facebook.Profile.getCurrentProfile() == null){
mProfileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(com.facebook.Profile oldProfile, com.facebook.Profile currentProfile) {
mProfileTracker.stopTracking();
}
};
mProfileTracker.startTracking();
} else {
com.facebook.Profile profile = com.facebook.Profile.getCurrentProfile();
}
try {
URL image_value = new URL("http://graph.facebook.com/" + loginResult.getAccessToken().getUserId() + "/picture?type=large");
Log.v(Constants.TAG, image_value + "");
} catch (Exception e) {
}
}
@Override
public void onCancel() {
Log.e("TAG", "wrong");
}
@Override
public void onError(FacebookException error) {
Log.e("TAG", "wrong");
}
});
Where facebookLoginButton is LoginButton and callbackManager is CallbackManager Please help me thanks in advance.
You can get the gender of any user using Open Graph even without any access_token. GET https://graph.facebook.com/userid json_decode the data gender will be in the `gender` element of the returned array.
What the app do is sign in (Sign In API included name and email) first, then request birthday & gender (People API) authentication, and save it to SharedPreferences for reuse on next launch. Finally it will print basic info and advanced (gender & birthday) info.
The only way to see birthdays on the app is by searching that person's name and going to their profile If they’ve enabled their Facebook friends or the public to see their birthday then you should be able to see it Facebook has made it impossible to download your friend’s birthday information from Facebook due to data privacy concerns.
Requires App Review. The user_gender permission allows your app to read a person's gender as listed in their Facebook profile. The allowed usage for this permission is to render pronouns and to personalize a person's experience based on gender, for example dating, shopping and fashion apps.
Enter Application display name and your contact email address . Then click on Create App ID . 6. At front of Facebook Login click on Get Started. 7. On Choose Platform Window click on Android . 8. Now skip to the 2nd step and open your Project’s build.gradle (Module:app) file.
gender
& birthday
needs app review.Apps that Require App Review
Your app requires review if it uses the following functionality:
Facebook Login and also asks for a person's birthday, location, hometown, gender, age range, or link to profile
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