Skip to content

Instantly share code, notes, and snippets.

@Ferrmolina
Created May 24, 2016 03:56
Show Gist options
  • Save Ferrmolina/3bb75778f37037726e66035151b7e9c8 to your computer and use it in GitHub Desktop.
Save Ferrmolina/3bb75778f37037726e66035151b7e9c8 to your computer and use it in GitHub Desktop.
Get Name, ID and Email - Facebook SDK - Android
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
GraphRequest request = GraphRequest.newMeRequest(
accessToken,
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
final JSONObject object,
GraphResponse response) {
// Application code
final JSONObject jsonObject = response.getJSONObject();
String nombre = "";
String email = "";
String id = "";
try {
nombre = jsonObject.getString("name");
email = jsonObject.getString("email");
System.out.println(nombre);
System.out.println(email);
System.out.println(id);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
request.setParameters(parameters);
request.executeAsync();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment