Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid already-authorized in Android Facebook SDK

I'm getting a completely useless page when I use the Single Sign on for Facebook's Android SDK.

"You have already authorized happyapp. Press "Okay" to continue.

This page would destroy user experience. How the heck do I get rid of it. Lots of people have been seeing this, but no solution is posted.

Even Facebook admits this is a problem, see: http://forum.developers.facebook.net/viewtopic.php?id=84548

Does anyone know any work-around?

like image 467
hunterp Avatar asked Dec 21 '10 02:12

hunterp


People also ask

How do I logout of Facebook SDK on Android?

So far, to log out Facebook programmatically, I used : Session session = Session. getActiveSession(); session. closeAndClearTokenInformation();

What SDK does Facebook use?

To learn more about using Facebook development tools, see App Development. The current version of the Facebook SDK for Android is version 14.1. 1 and requires the Android API 15.

How can I update my Facebook SDK?

Login into Facebook and navigate to https://developers.facebook.com/apps/ Select the App you want to upgrade (you might have access to multiple apps) Click Settings > Advanced. Select the latest version under the Upgrade API Version section for both “Upgrade All Calls” and “Upgrade Calls for App Roles”


2 Answers

The way I did it (without additional OAuth solution) was to store off the access token in preferences as Kieveli suggested. When the main activity starts, look up the token from preferences, if it's not there initiate the authorization process and store the resulting token in preferences.

The harder part is to handle token expiration or de-authorization of your app (ie. the token is in preferences, but is no longer valid).

For that case, with every FB API/graph invocation, check for an exception indicating authentication failed. If it fails, initiate the authorization/token storing procedure again.

like image 120
P. Taylor Goetz Avatar answered Oct 07 '22 07:10

P. Taylor Goetz


using the suggestion here, this is the code that worked for me, hope it helps someone

before login do this

SharedPreferences prefs= PreferenceManager.getDefaultSharedPreferences(FacebookLogin.this);                          String access_token = prefs.getString("access_token", null);                          Long expires = prefs.getLong("access_expires", -1);                           if (access_token != null && expires != -1)                         {                             facebook.setAccessToken(access_token);                             facebook.setAccessExpires(expires);                         }                           if (!facebook.isSessionValid())                         {                             facebook.authorize(FacebookLogin.this, new DialogListener() { ... 

after you successfully logged in do this

String token = facebook.getAccessToken(); long token_expires = facebook.getAccessExpires();  SharedPreferences prefs= PreferenceManager.getDefaultSharedPreferences(FacebookLogin.this);  prefs.edit().putLong("access_expires", token_expires).commit();  prefs.edit().putString("access_token", token).commit(); 
like image 21
max4ever Avatar answered Oct 07 '22 07:10

max4ever