[ SOLVED MYSELF. SEE THE ANSWER FOR SOLUTION. ]
I used android facebook sdk 3.5 in my application for login. Now when user logout from facebook in my application, i simply follwing below codes to logout.
session=new Session(context);
Session.setActiveSession(session);
session.closeAndClearTokenInformation();
Now, if user again try to login to facebook, I want to show login box as another user instead of doing login automatically from sessioncache.
[ remember that when your device has facebook application installed. Above problem only exist when device has facebook application else it is working fine. ]
I have googled this problem but not found the solution for SDK 3.5 . So how to force to show login box when user try to login again??
The only idea i got is we need to deauthorize our application on logout. So it will be asked to enter login again. Is this corret? if yes, then how can we deauthorize our app using sdk 3.5 ?
Finally i succeed in revoking authorization. here is the code.
Request deAuthorizeRequest=new Request(session, "/me/permissions", null, HttpMethod.DELETE, new Callback() {
#Override
public void onCompleted(Response response) {
((BaseFunctions) getActivity()).Log("unlink account : "+response.toString());
session.closeAndClearTokenInformation();
}
});
deAuthorizeRequest.executeAsync();
But it seems that this solved my problem partial. It is not showing login box dialog. Need to find solution for it. :)
Related
How to remove all application data on react native?
Not only AsyncStorage.clear().
I mean deleting application data like through settings > application.
I have faced EUNSPECIFIED error code with react-native-fbsdk.
First I logged in with my facebook account,
Second I logged out from it,
Third I relogin with this account (It works well)
And then I logged out again,
And I tried to log in with another facebook account,
But I faced EUNSPECIFIED error.
But after deleting all app data (not uninstall) through settings > application,
I can login with another facebook account.
I have to delete all applilcation data when logged out from my react native application.
OR
I have to fix this react-native-fbsdk's bug (or I guess fbsdk is caching some data....)
Already I put AsyncStorage.clear() when logout, No changes..
Appreciate for your help...
I had this problem with FBSDK as well and the problem is that when you login with facebook, the SDK creates an AccessToken linked to the old user. Therefore, when you try to login with another account, it throws this weird error message.
What you have to do is to logout the user on the fbAPI. The code below is how you do it:
// Remove FbAccessToken when the user logout.
logoutFromFB(){
if (AccessToken.getCurrentAccessToken() != null) {
LoginManager.logOut()
}
}
I hope it helps!
I integrated Facebook login into my app, and It works fine. The issue is with the logout.
When I open the Facebook app on my device, I can perform a logout, so that the next time I open It, It will ask my If I want to login with my usual account, login with another account or even create a new account. Good, that is expected.
But this doesn't happen with my app. I mean, If the user opens my app, clicks in "logout" and the code below is ran
// Initialize Facebook SDK on the beginning.
FacebookSdk.sdkInitialize(this.getApplicationContext());
...
// Logout on user choice.
LoginManager.getInstance().logOut();
the next time he is back on the app and clicks to login he will be logged in directly with his account, he won't be asked with each account he wants to login.
I image that I need to clear all informations (tokens?) that are saved, which are being used into this directly login. Is this correct? If yes, how can I do it?
Thank you,
I am using this method. It's for SDK 4.6.0, but I guess it should be the same as 4.0. If not, just upgrade ;)
public void logoutFromFacebook(final LogoutFacebookListener listener) {
if (AccessToken.getCurrentAccessToken() == null) {
// already logged out
listener.onLoggedOutFromFacebook();
return;
}
new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions/", null, HttpMethod.DELETE, new GraphRequest
.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
LoginManager.getInstance().logOut();
listener.onLoggedOutFromFacebook();
}
}).executeAsync();
}
Listener:
public interface LogoutFromFacebookListener {
void onLoggedOutFromFacebook();
}
It seams like when you trying to login, facebook sdk uses your web browser (chrome, etc) in your case. And when you call LoginManager.getInstance().logOut(); you do logout just from facebook sdk, but you are still staying loggedin in your web browser. The Android and iOS SDKs don't currently support re-authentication. Hope they will be in future ;)
I implemented Facebook login button as described in https://developers.facebook.com/docs/facebook-login/android developer guide with profile and email read permissions.
When i press login button, Facebook app opens up and then I can log in and can get user data from Facebook. After this point, Facebook button turns to Log out button automatically. And when it is pressed, it logs out. So far, it works well.
Once Facebook log out done in my app side, and want to re-login with Facebook button, Facebook fails with key hash error. If I go to account settings in Facebook app, and remove my app from list then re-login returns success.
I also tried the solution here Android Facebook app logout issue but it didn't work either.
To clear, I use this code (found shared pref name in AccessTokenCache class):
SharedPreferences fbSharedPreferences = this.getSharedPreferences("com.facebook.AccessTokenManager.SharedPreferences", 0);
if (fbSharedPreferences != null) {
fbSharedPreferences.edit().clear().commit();
}
I'm using Facebook SDK 4.5. I'm testing with a real Facebook account. My app keys and hashes are set in Facebook app settings.
P.S. Question title is influenced from Facebook Login-Logout Issue Invalid Key Hash Error, While Trying to Login Again (which does not have a solution).
I was having the same issue, you need to delete app from facebook app and then logout. Following function will do the trick.
public void disconnectFromFacebook() {
if (AccessToken.getCurrentAccessToken() == null) {
return; // already logged out
}
new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions/", null, HttpMethod.DELETE, new GraphRequest
.Callback() {
#Override
public void onCompleted(GraphResponse graphResponse) {
LoginManager.getInstance().logOut();
}
}).executeAsync();
}
I am just new to Android Application and trying my hands on implementing Facebook login within my app. Successfully implementation of login but logout causes some trouble.
The first time I logged in it requested for my details and then signed in.
Next time I do the same it no more asks for my details, by default it logs me in with account.
What if I want to sign in with different user?
I have searched the net for solution and found out that -
- I cannot use Session as they were available only till Facebook SDK 3.X.X not for SDK 4.X.X
- I have tried calling LoginManager.getInstance().logOut();
(But I still have doubts where to use it.)
- I have also tried
new GraphRequest(AccessToken.getCurrentAccessToken(),"/me/permissions/", null, HttpMethod.DELETE,
new GraphRequest.Callback(){
#Override
public void onCompleted(GraphResponse graphResponse) {
LoginManager.getInstance().logOut();
}
}).executeAsync();
and I have also tried doing this :
` AccountManager am = AccountManager.get(context);
Account[] localAccounts = am.getAccounts();
for (int i=0; i<localAccounts.length; i++){
if (localAccounts[i].type.equals("com.facebook.auth.login")){
am.removeAccount(localAccounts[i], null, null);
}
}`
So it'll be really great if somebody could guide me properly on how to carry out a successful logout operation on Facebook, I'll be highly obliged.
Thanks in advance :)
The SDK will use either of two options to let the user log in to your app on Android:
using the native login dialog (which is powered by the Facebook app that is installed on the device)
using a webview-based dialog if the Facebook app is not installed on the device.
Both options depend on you being signed into Facebook in another app (your browser/your native Facebook app).
If you want to log into your app as a different user (there is really no need, because android system user profiles should be considered personal and individually owned), you need to go to the app you use for Facebook (native Facebook app/browser) and switch to a different profile there. After that you should be able to log into your app with that other profile.
Other than that, it is not your app's job to log people out of their Facebook.
first, I'am sorry. i can't english well.
i have a problem in facebook sdk.
now i am developing login with facebook sdk.
and logout too.
but i can't find unlink api between my-app and facebook.
for example, some user using my app do not want to use my app more.
so he needs to ban me(or my app) in order to protect his data on facebook.
do you understand me? T.T please help me.
following flow is when the user unlinks the app himself directly.
but i want to do this in my app menu with login, logout, etc.
Menu Flow : (in facebook app settings) Apps -> Logged in with Facebook -> (choice a app) -> Remove App
FB.api("/me/permissions","DELETE",function(response){
console.log(response); //gives true on app delete success
});
You need a active access token of user to do this
Using Facebook sdk
new Request(
session,
"/me/permissions/{permission-to-revoke}",
null,
HttpMethod.DELETE,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();