Android 谷歌Oauth2,can';无法检索一次性授权码

Android 谷歌Oauth2,can';无法检索一次性授权码,android,oauth-2.0,google-oauth,Android,Oauth 2.0,Google Oauth,我有一个android应用程序,通过请求一个一次性授权码来访问谷歌服务。每次用户登录时,都会从Google检索身份验证代码。 它在一段时间内运行良好,但对特定用户停止了工作。 该用户不断获得UserRecoverableAuthException,因此谷歌权限请求屏幕不断显示。 当我尝试获取此用户的正常访问令牌时,没有问题 我使用的代码是: protected Void doInBackground(Void... params) { try

我有一个android应用程序,通过请求一个一次性授权码来访问谷歌服务。每次用户登录时,都会从Google检索身份验证代码。 它在一段时间内运行良好,但对特定用户停止了工作。 该用户不断获得
UserRecoverableAuthException
,因此谷歌权限请求屏幕不断显示。 当我尝试获取此用户的正常访问令牌时,没有问题

我使用的代码是:

protected Void doInBackground(Void... params) 
            {
             try 
             {
                // Obtaining normal access token for testing propose.
                String tempToken  = GoogleAuthUtil.getToken(getApplicationContext(), mAccountName, "oauth2:https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/calendar");
                NLog.i(TAG, "Got token2: "+tempToken);          
                // Obtaining One time auth code
                String scope = String.format("oauth2:server:client_id:%s:api_scope:%s",CLIENT_ID, TextUtils.join(" ", SCOPES));
                mServerToken = GoogleAuthUtil.getToken(getApplicationContext(), mAccountName, scope);
                NLog.i(TAG, "Got code: "+mServerToken);
                sendGoogleLoginResult(RESULT_OK, null, mServerToken);
                finish();
            } 
             catch (UserRecoverableAuthException e) 
             {
                if (e !=null && e.getIntent() != null && authExceptionCount <3)
                {
                    authExceptionCount++;
                    Intent recoveryIntent = e.getIntent();
                    startActivityForResult(recoveryIntent, GOOGLE_RECOVERY_ACTIVITY_REQUEST);
                }
                else
                {
                    Log.i(TAG, "UserRecoverableAuthException but there was no intent: ", e);
                    sendGoogleLoginResult(RESULT_CANCELED, null, mServerToken);
                    finish();
                }
            } 
             catch (IOException e) {
                Log.i(TAG, "transient error encountered: ", e);
                sendGoogleLoginResult(RESULT_CANCELED, null, mServerToken);
                finish();

            } catch (GoogleAuthException e) {
                // This is likely unrecoverable.
                 Log.e(TAG, "Unrecoverable authentication exception: " + e.getMessage(), e);
                 sendGoogleLoginResult(RESULT_CANCELED, null, mServerToken);
                 finish();
            }
            return null;
        }
受保护的Void doInBackground(Void…params)
{
尝试
{
//正在获取用于测试的正常访问令牌。
字符串testoken=GoogleAuthUtil.getToken(getApplicationContext(),mAccountName,“oauth2:https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/calendar");
NLog.i(标记“Got token2:+tentoken”);
//获取一次性身份验证代码
String scope=String.format(“oauth2:server:client\u id:%s:api\u scope:%s”,client\u id,TextUtils.join(“,SCOPES));
mServerToken=GoogleAuthUtil.getToken(getApplicationContext(),mAccountName,scope);
NLog.i(标记,“Got代码:”+mServerToken);
sendGoogleLoginResult(结果_OK,null,mServerToken);
完成();
} 
捕获(UserRecoverableAuthe异常)
{

如果(e!=null&&e.getIntent()!=null&&authExceptionCount,但您有两个对getToken()的调用在同一个try/catch中,那么您如何知道是哪一个向您发送了UserRecoverableAuthException…哦,我想您可以在logcat中查看。您是说这对某些用户有效,但对其他用户无效?它不适用于某个奇怪/不同的设备上的用户吗?您可以提供的任何进一步信息都会很有用。对,我可以通过查看这两个调用都是出于测试的原因(添加了第一个来检查它是否发生在正常的令牌请求上,但显然没有)。问题似乎取决于设备,因为所有用户都无法连接到此设备,也无法成功连接到其他设备。如果问题出现在特定设备上,则您可能没有该设备上的正确代码/更新,这就是为什么会出现异常。嗯,您可能会进入故障设备上的设置/应用程序并检查版本在Google Play服务上,你可以通过从Play商店刷新来修复它。