I’m trying to get name and email from facebook login.
I’m using: compile 'com.facebook.android:facebook-android-sdk:4.+'
I can get into onSuccess
but the code does not get into GraphRequest and I think that’s why I can’t get name and email (I’d also like get Profile picture)
I got the autogenerated code (GraphRequest) from facebook developer Explorer Api Graph
public class LoginActivity
{
LoginButton buttonLoginFacebook;
@Nullable
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
buttonLoginFacebook = (LoginButton) findViewById(R.id.connectWithFbButton);
buttonLoginFacebook.setReadPermissions(Arrays.asList(
"public_profile", "email"));
FacebookSdk.setIsDebugEnabled(true);
FacebookSdk.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
FacebookSdk.addLoggingBehavior(LoggingBehavior.REQUESTS);
buttonLoginFacebook.setOnClickListener(this);
buttonLoginFacebook.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
//----->THE CODE JUMPS FROM HERE
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
mensajeFACEBOOK="TRYING TO GET NAME";
}
});
//----->TO HERE
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,first_name,last_name");
request.setParameters(parameters);
request.executeAsync();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
}
});
}
}
2
Answers
This is how i do it. Hope this helps.
Actually
GraphRequest.executeAsync()
is an async method with a callbackonCompleted
so to read the data you need to do it inside the callback.Also included the profile picture field
picture.width(150).height(150)
as you asked