I implemented the facebook login for android according to their documentation
The problem is that after the user enter its credentials (1 dialog) for login and confirm the app permissions (2 dialog) the facebook connect simply return to the (1 dialog) where its request the credentials again. why is this happening?
In the facebook user i can see the app in the apps list
This is my code:
CallbackManager callbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions("public_profile","user_friends");
// Callback registration
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
Log.i(Utils.TAG,"succesfull login to facebook");
// App code
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
Log.i("LoginActivity", response.toString());
try {
}catch (Exception e)
{ Log.i(Utils.TAG, e.getMessage());
}
}
});
}
@Override
public void onCancel() {
// App code
Log.i(Utils.TAG,"onCancel login to facebook");
}
@Override
public void onError(FacebookException exception) {
// App code
Log.i(Utils.TAG,"onError login to facebook");
Log.i(Utils.TAG,exception.getMessage());
}
});
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// LoginManager.getInstance().logInWithReadPermissions((Activity)m_context, Arrays.asList("public_profile", "email", "user_birthday", "user_friends"));
LoginManager.getInstance().logInWithReadPermissions((Activity)m_context, Arrays.asList("public_profile", "user_friends"));
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i(Utils.TAG,"onActivityResult called");
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
I should mention that none of the call backs is called during the login flow only when i dismiss the dialog
Yes, It is because you are using login button and Login Manager both.. You have to choose only one from them.. because they both have same functionality. I suggest you to remove Login Manager code from here.
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// LoginManager.getInstance().logInWithReadPermissions((Activity)m_context, Arrays.asList("public_profile", "email", "user_birthday", "user_friends"));
LoginManager.getInstance().logInWithReadPermissions((Activity)m_context, Arrays.asList("public_profile", "user_friends"));
}
});
and
oginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
Log.i(Utils.TAG,"succesfull login to facebook");
// App code
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
Log.i("LoginActivity", response.toString());
try {
}catch (Exception e)
{ Log.i(Utils.TAG, e.getMessage());
}
}
});
}
@Override
public void onCancel() {
// App code
Log.i(Utils.TAG,"onCancel login to facebook");
}
@Override
public void onError(FacebookException exception) {
// App code
Log.i(Utils.TAG,"onError login to facebook");
Log.i(Utils.TAG,exception.getMessage());
}
});