Android Google+ integration - repeated UserRecoverableAuthException

前端 未结 8 1699
独厮守ぢ
独厮守ぢ 2020-11-30 00:55

We have contacted Google about this and we are on chat

The issue seems to be fixed for devices except Samsung phones.

I\'m

相关标签:
8条回答
  • 2020-11-30 01:28

    Its too late to reply but it may help to people having same concern in future.

    They have mentioned in the tutorial that it will always throw UserRecoverableAuthException when you invoke GoogleAuthUtil.getToken() for the first time. Second time it will succeed.

    catch (UserRecoverableAuthException e) {
      // Requesting an authorization code will always throw
      // UserRecoverableAuthException on the first call to GoogleAuthUtil.getToken
      // because the user must consent to offline access to their data.  After
      // consent is granted control is returned to your activity in onActivityResult
      // and the second call to GoogleAuthUtil.getToken will succeed.
      startActivityForResult(e.getIntent(), AUTH_CODE_REQUEST_CODE);
      return;
    }
    

    i used below code to get access code from google.

    execute this new GetAuthTokenFromGoogle().execute(); once from public void onConnected(Bundle connectionHint) and once from protected void onActivityResult(int requestCode, int responseCode, Intent intent)

    private class GetAuthTokenFromGoogle extends AsyncTask<Void, Integer, Void>{
            @Override  
            protected void onPreExecute()  
            {  
    
            }
            @Override
            protected Void doInBackground(Void... params) {
                // TODO Auto-generated method stub
    
                try {
                    accessCode = GoogleAuthUtil.getToken(mContext, Plus.AccountApi.getAccountName(mGoogleApiClient), SCOPE);
                    new ValidateTokenWithPhoneOmega().execute();
                    Log.d("Token  -- ", accessCode);
                } catch (IOException transientEx) {
                    // network or server error, the call is expected to succeed if you try again later.
                    // Don't attempt to call again immediately - the request is likely to
                    // fail, you'll hit quotas or back-off.
    
                    return null;
                } catch (UserRecoverableAuthException e) {
                    // Recover
                    startActivityForResult(e.getIntent(), RC_ACCESS_CODE);
                    e.printStackTrace();
                } catch (GoogleAuthException authEx) {
                    // Failure. The call is not expected to ever succeed so it should not be
                    // retried.
                    authEx.printStackTrace();
                    return null;
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                return null;  
            }
    
            @Override  
            protected void onPostExecute(Void result)  
            { 
            }
        }
    
    0 讨论(0)
  • 2020-11-30 01:30

    you should startactiviy in UI thread

    try {
        ....
    } catch (IOException transientEx) {
        ....
    } catch (final UserRecoverableAuthException e) {
        ....
        runOnUiThread(new Runnable() {
            public void run() {         
                startActivityForResult(e1.getIntent(), AUTH_CODE_REQUEST);
            }
        });
    }
    
    0 讨论(0)
提交回复
热议问题