I am trying to implement facebook login using latest facebook SDK 4.0.It is only returning User-ID and User-name. Below is the code which I have implemented using GRAPH APIs.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button);
textView = (TextView) view.findViewById(R.id.textView);
List<String> permissions = new ArrayList<>();
//permissions.add("user_friends");
permissions.add("email");
//permissions.add("user_birthday");
loginButton.setReadPermissions(permissions);
loginButton.setFragment(this);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest.newMeRequest(
loginResult.getAccessToken(),new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
if (graphResponse.getError() != null) {
// handle error
} else {
String email = jsonObject.optString("email");
String id = jsonObject.optString("id");
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + id,
null,
HttpMethod.GET,
new GraphRequest.Callback() {
@Override
public void onCompleted( GraphResponse graphResponse) {
Log.d("FACEBOOK LOGIN","graph response" +graphResponse.toString());
}
}
).executeAsync();
Log.d("FACEBOOK LOGIN ","email id and the user_id of the looged in user is = ::" + email+" ::"+id+"" +
"JsonObject from facebook i am getting is :" +jsonObject.toString());
// send email and id to your web server
}
}
}).executeAsync();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
}
});
}
Also I tried using GRAPH API EXPLORER, where it is showing me my email address as well as birthday and gender too. Below is the snapshot of it
Try this .
Its done.!!