Facebook logout does not work Android [Facebook sdk 4] - android

I'm developing a game for Android that has Facebook login and I faced the following weird behaviour when trying to logout:
if user press Facebook logout button, closes the app and then reopens again, the user is still logged in (= access token still valid).
As a test, I checked the access token after logout and it is null as it should be, but if I close and reopen the app then the access token is again not null.
It seems that Facebook caches the access token and takes it from cache even after logout.
I tried using native Facebook button and also LoginManager.getInstance.logout(); I have initialized Facebook sdk on the top of the onCreate, before setContent() and I followed the procedure on Facebook docs, but same result.
I'm using Facebook sdk 4.6.0 and I faced this problem on Android 4.2.2 and 4.4.2.
EDIT
Here's the code:
- Facebook button:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_settings);
btnFacebookLogout.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException e) {
}
});
}
- normal button:
btnNormalLogout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LoginManager.getInstance().logOut();
}
});
Any suggestion?
Thanks in advance

Well, i`ve been fighting that damn sdk for about an hour and discovered a simple workaround for that logout issue.
Just try to do the following:
LoginManager.getInstance().setLoginBehavior(LoginBehavior.WEB_ONLY)
Pros: LoginManager.getInstance().logOut() works fine in this case.
Cons: the authentication will always appear in a webview dialog.

Related

android snapchat login kit's LoginResultCallback doesn't work normally

I implemented the snapchat login in my Android app by referring to the snapchat login kit sdk guide.
I refer to the below code that uses a custom button.
// Get the login API
SnapLogin snapLogin = SnapLoginProvider.get(getContext());
View yourButtonView = findViewById(...);
yourButtonView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Start token grant
snapLogin.startTokenGrant(new LoginResultCallback() {
#Override
public void onStart() {
// Here you could update the UI to show login start
}
#Override
public void onSuccess(#NonNull String accessToken) {
// Here you could update the UI to show login success
}
#Override
public void onFailure(#NonNull LoginException exception) {
// Here you could update the UI to show login failure
}
});
}
});
Call startTokenGrant api to complete authentication in snapchat.
After authentication, callback is called when returning to my app.
Step 1 goes well.
But intermittently, the callback is not called.
I thought this was an error in the sdk, but I saw that it works normally in other apps.
Has anyone had an experience where the callback never gets called?
If yes, please help how to solve it.
(I'm developing using dev clientId right now, will this have any effect?)

android app integration with facebook review compulsory?

I have written a code to login using facebook button sdk 4.0. I am able to login/logout. There is an activity for user from where user can share their locally saved picture to facebook. Sharing is possible if native facebook app is installed. But not in case facebook is not installed. So I tried to use ShareApi for sharing pictures via web view. But it requires publish actions permission. So I just written following code to get permission. It opens a window where it ask for per ok and cancel with my app name. After pressing ok button it always falls in onCancel case automatically.
I have read somewhere that you need to submit your app for review to facebook team in order to take publish actions permission. Is this only reason i am not getting success after trying almost 18 hours.?? Please help me friends.
List<String> permissionNeeds = Arrays.asList("publish_actions");
LoginManager loginManager = LoginManager.getInstance();
loginManager.logInWithPublishPermissions(activity,permissionNeeds);
loginManager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
System.out.println("onSuccess" + loginResult);
sharePhotoToFacebook();
}
#Override
public void onCancel() {
System.out.println("onCancel");
}
#Override
public void onError(FacebookException error) {
System.out.println("onError"+error);
}
});

Facebook Login on Android App

I have seen numerous stackoverflow posts but none of them seem to be helping me in this problem.
When I try to login using facebook, the facebook app opens, asks for permissions and then when I click OK, everything goes into background. There is nothing in the logs.
Things that I have already tried:
I have created app on Facebook developer console
Added Android as platform on Settings page, added package name, class name and generated key hash. Then i also added the key hash from the logcat error with = at the end.
I have added my email address in contact, and made my app go live in Status & Review.
I have installed and logged in to Facebook app on my android device.
I have tried deleting my debug.keystore, and generating new hash
I have tried deleting Facebook developer app and creating it from scratch
I am using LoginManager to sign-in to facebook from my android app.
Here is my code for login:
private void loginWithFacebook() {
final LoginManager loginManager = LoginManager.getInstance();
CallbackManager callbackManager = CallbackManager.Factory.create();
loginManager.registerCallback(
callbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(final LoginResult loginResult) {
Log.e("WelcomeScreen", "onSuccess");
}
#Override
public void onCancel() {
Log.e("WelcomeScreen", "onCancel");
}
#Override
public void onError(FacebookException e) {
Log.e("WelcomeScreen", "onError");
}
}
);
loginManager.logInWithReadPermissions(this, Arrays.asList("public_profile"));
}
I have already done this in onCreate:
FacebookSdk.sdkInitialize(getApplicationContext());
I figured out the problem. In my manifest, I had specified noHistory to true for the activity where I was expecting the activity result back from Facebook activity, but since the activity is destroyed once it launches another activity, the app was shutting down. Removing the hoHistory resolved the issue.

How can I switch authorized facebook user with Facebook Android SDK?

I have successfully implemented authorization with facebook in my native android app.
Now I have following problem:
User logout from my app and I call facebook sdk logout method. But when user presses login button it automatically redirects back to my app without showing "Already authorized" window, so he cannot switch to another user.
Is that normal behavior or I've made something wrong? How can I solve this issue?
If you would like to switch to another user, you can refer to the "SwitchUserSample" in Facebook SDK for Android.
Here is some example code fyi.
Session currentSession = Session.getActiveSession();
currentSession.closeAndClearTokenInformation();
newSession = new Session.Builder(LoginActivity.this).build();
newSession.openForRead(new Session.OpenRequest(LoginActivity.this)
.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO)
.setCallback(statusCallback));
No that's not default we can switch user. While you are doing Logout you are not clearing credentials properly so such problems arise , so you need to remove credentials perfectly.
You should got through the HackBook code given by Facebook for all features , where you have to save you Facebook object in SessionStore class and handle it accordingly :
private class SessionListener implements AuthListener, LogoutListener {
#Override
public void onAuthSucceed() {
setImageResource(R.drawable.logout_button);
SessionStore.save(mFb, getContext());
}
#Override
public void onAuthFail(String error) {
}
#Override
public void onLogoutBegin() {
}
#Override
public void onLogoutFinish() {
SessionStore.clear(getContext());
setImageResource(R.drawable.login_button);
}
}

logging in to facebook from my app works on emulator but not on device

This is my code for logging in to facebook.
mLoginButton = (LoginButton) findViewById(R.id.login);
// restore session if one exists
SessionStore.restore(Utility.mFacebook, this);
SessionEvents.addAuthListener(new FbAPIsAuthListener());
SessionEvents.addLogoutListener(new FbAPIsLogoutListener());
/*
* Source Tag: login_tag
*/
mLoginButton.init(this, AUTHORIZE_ACTIVITY_RESULT_CODE, Utility.mFacebook, permissions);
if (Utility.mFacebook.isSessionValid()) {
requestUserData();
}
public class FbAPIsAuthListener implements AuthListener {
//#Override
public void onAuthSucceed() {
requestUserData();
}
//#Override
public void onAuthFail(String error) {
mText.setText("Login Failed: " + error);
}
}
/*
* The Callback for notifying the application when log out starts and
* finishes.
*/
public class FbAPIsLogoutListener implements LogoutListener {
//#Override
public void onLogoutBegin() {
mText.setText("Logging out...");
}
///#Override
public void onLogoutFinish() {
mText.setText("You have logged out! ");
mUserPic.setImageBitmap(null);
}
}
On emulator it works perfect. I have tried in ton 3 devices, that have already facebook installed and here is the problem.
it just spinning aroun on loading and it does nothing. I see the login button again.
Then i tried to logout from the original facebook application, and when pressing the login button on my app, i see the login window but now that I used to see when logging in the emulator but the login window of the original facebook application. Like is has started this one.
the code I am using is taken from the hackbook.java
The Platform Status says that there's a problem with the SSO.
The SSO only works if you have the facebook application installed on the android device, and what you describe fits right into all of this.
On the emulator you don't have the facebook application, and so when your application tries to log the user in it uses the dialog it has in the sdk instead of using the SSO process that ships with the fb application.
On the device how ever you said that you do have the fb app, and so the SSO kicks in and, at least currently, there's a problem with it.
Try to uninstall the facebook application on the device or maybe just cancel the SSO, i.e.: How to disable Facebook single sign on for android - Facebook-android-sdk
You need to generate the hash key of your system and just place it by editing the existing facebook App.

Categories

Resources