I am using customize Facebook login button .this is my code. I'm using session manager to store email and name for entire app.I have used logout button in third activity .
How to logout from Facebook
public void FB_Login(View view){
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "email"));
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// AccessToken.getCurrentAccessToken().getPermissions();
// Profile profile = Profile.getCurrentProfile();
// String firstName = profile.getFirstName();
// System.out.println(profile.getProfilePictureUri(20,20));
// System.out.println(profile.getLinkUri());
// App code
AccessToken.getCurrentAccessToken().getPermissions();
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
try {
email = object.getString("email");
name=object.getString("name");
// Creating user login session
// For testing i am stroing name, email as follow
// Use user real data
session.createLoginSession(name, email);
// Staring MainActivity
if (session.isLoggedIn()) {
in = new Intent(HomePageActivity.this, HomeSearchActivity.class);
in.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// Add new Flag to start new Activity
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(in);
finish();
}
} catch (JSONException e) {
e.printStackTrace();
}
Log.v("LoginActivity", response.toString());
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender, birthday");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
// App code
Log.v("LoginActivity", "cancel");
}
@Override
public void onError(FacebookException exception) {
// App code
Log.v("LoginActivity", exception.getCause().toString());
}
});
}
Anyone help me. please.
You can logout from Facebook
using Facebook Graph API
.
LoginManager.getInstance().logOut();
I hope it helps!
You need to use :
LoginManager.getInstance().logOut();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With