oauth 2.0 - Android Google+ integration - repeated UserRecoverableAuthException -


we have contacted google , we on chat

the issue seems fixed devices except samsung phones.

i'm adding google+ sign in option app per official instructions. once user has selected account server retrieve google+ profile info , update profile on our site match.

the first part - having user select google account locally - seems work fine. when try request token selected account, google auth dialog displays appropriate parameters; however, when authorize app using dialog , re-request token, googleauthutil.gettoken(...) again throws userrecoverableauthexception (needpermission, not googleplayservicesavailabilityexception) , same dialog asking me approve!

this behavior present on samsung s3 running android 4.1.1 (with 3 google accounts) , acer a100 running 4.0.3. not present on htc glacier running 2.3.4. instead, htc glacier gives me valid auth code. devices have latest iteration of google play services installed , using different google+ accounts.

anyone seen before? can start debugging?

here's complete code - awry?

public class mygoogleplusclient { private static final string log_tag = "gplus"; private static final string scopes_login = scopes.plus_login + " " + scopes.plus_profile; private static final string activities_login = "http://schemas.google.com/addactivity"; private static mygoogleplusclient mygplus = null; private baseactivity mrequestingactivity = null; private string mselectedaccount = null;  /**  * gplus singleton  * @return gplus  */ public synchronized static mygoogleplusclient getinstance() {     if (mygplus == null)         mygplus = new mygoogleplusclient();     return mygplus; }  public boolean login(baseactivity requester) {     log.w(log_tag, "starting login...");     if (mrequestingactivity != null) {         log.w(log_tag, "login attempt in progress.");         return false; // cannot launch new request; in progress     }      mrequestingactivity = requester;     if (mselectedaccount == null) {         intent intent = accountpicker.newchooseaccountintent(null, null, new string[]{googleauthutil.google_account_type}, false,                 null, googleauthutil.google_account_type, null, null);         mrequestingactivity.startactivityforresult(intent, baseactivity.request_gplus_select);     }     return true; }  public void logincallback(string accountname) {     mselectedaccount = accountname;     authorizecallback(); }  public void logout() {     log.w(log_tag, "logging out...");     mselectedaccount = null; }  public void authorizecallback() {     log.w(log_tag, "user authorized");      asynctask<void, void, string> task = new asynctask<void, void, string>() {         @override         protected string doinbackground(void... params) {             string token = null;             try {                 bundle b = new bundle();                 b.putstring(googleauthutil.key_request_visible_activities, activities_login);                 token = googleauthutil.gettoken(mrequestingactivity,                         mselectedaccount,                         "oauth2:server:client_id:"+constants.google_plus_server_oauth_client                         +":api_scope:" + scopes_login,                         b);             } catch (ioexception transientex) {                 // network or server error, try later                 log.w(log_tag, transientex.tostring());                 oncompletedloginattempt(false);             } catch (googleplayservicesavailabilityexception e) {                 log.w(log_tag, "google play services not available.");                 intent recover = e.getintent();                 mrequestingactivity.startactivityforresult(recover, baseactivity.request_gplus_authorize);             } catch (userrecoverableauthexception e) {                 // recover (with e.getintent())                 log.w(log_tag, "user must approve "+e.tostring());                 intent recover = e.getintent();                 mrequestingactivity.startactivityforresult(recover, baseactivity.request_gplus_authorize);             } catch (googleauthexception authex) {                 // call not ever expected succeed                 log.w(log_tag, authex.tostring());                 oncompletedloginattempt(false);             }              log.w(log_tag, "finished task; token "+token);             if (token != null) {                 authorizecallback(token);             }              return token;         }      };     task.execute(); }  public void authorizecallback(string token) {     log.w(log_tag, "token obtained: "+token);     // <snipped - more stuff involving connecting server , resetting state locally> }  public void oncompletedloginattempt(boolean success) {     log.w(log_tag, "login attempt "+(success ? "succeeded" : "failed"));     mrequestingactivity.hideprogressdialog();     mrequestingactivity = null; } } 

i've had issue while , came proper solution.

string token = googleauthutil.gettoken(this, accountname, scopestring, appactivities); 

this line either return 1 time token or trigger userrecoverableauthexception. on google plus sign in guide, says open proper recovery activity.

startactivityforresult(e.getintent(), recoverable_request_code); 

when activity returns result, come few extras in intent , new token resides :

@override protected void onactivityresult(int requestcode, int responsecode, intent intent) {     if (requestcode == recoverable_request_code && responsecode == result_ok) {         bundle = intent.getextras();         string onetimetoken = extra.getstring("authtoken");     } } 

with new onetimetoken given extra, can submit server connect properly.

i hope helps!


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -