I am developing an application in which i am having Facebook authentication on custom button. The code i done is as follows:
First i initialize facebook SDK in my activity onCreate() as:
// Facebook
FacebookSdk.sdkInitialize(this);
then i registered call back as:
// Facebook Login
mCallbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
// Get facebook data from login
try {
Bundle bundle = new Bundle();
String id = object.getString("id");
URL profile_pic = null;
try {
profile_pic = new URL("https://graph.facebook.com/" + id + "/picture?type=large");
bundle.putString("profile_pic", profile_pic.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
}
String firstName = object.getString("first_name");
String lastName = object.getString("last_name");
} catch(JSONException e) {
Log.d("FB","Error parsing JSON");
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id, first_name, last_name"); // ParĂ¡metros que pedimos a facebook
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
Toast.makeText(LoginScreenActivity.this, "Login Cancel", Toast.LENGTH_LONG).show();
}
@Override
public void onError(FacebookException exception) {
Toast.makeText(LoginScreenActivity.this, exception.getMessage(), Toast.LENGTH_LONG).show();
}
});
And on my custom button click:
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "user_friends", "email"));
And the on activity result code is :
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Facebook
if (mCallbackManager.onActivityResult(requestCode, resultCode, data)) {
return;
}
}
This works fine. I done the code of logout on other activity as :
LoginManager.getInstance().logOut();
The issue is: When i tried to login again with facebook it is not asking me for login with different credentials of facebook user. App directly do the login with the previous login details.
What i am missing? What should i do now.
Please guide me. Thank you in advance for you valuable suggestions.