2014-10-31 19 views
1

我正在嘗試爲我的後端開發具有客戶端Google oAuth2.0授權的應用。我已經完成了Google開發者控制檯所需的所有工作。 只要應用程序請求帶有GoogleAuthUtil.getToken()的授權令牌,Google就會一直要求離線訪問。我想一勞永逸地給予許可,所以授權過程變得沉默。讓GoogleAuthUtil停止詢問用戶離線訪問

以下是我在我的授權AsyncTask中使用的代碼。

protected String doInBackground(String... arg0) { 
    String token = null; 

    try { 
     token = GoogleAuthUtil.getToken(mainActivity, mEmail, "oauth2:server:client_id:"+clientId+":api_scope:https://www.googleapis.com/auth/plus.login"); 
    } catch (GooglePlayServicesAvailabilityException playEx) { 
     Dialog dialog = GooglePlayServicesUtil.getErrorDialog(
       playEx.getConnectionStatusCode(), 
       mainActivity, 
       1001); 
     dialog.show(); 
    } catch (UserRecoverableAuthException recoverableException) { 
     Intent recoveryIntent = recoverableException.getIntent(); 
     mainActivity.startActivityForResult(recoveryIntent,1001); 
     // Use the intent in a custom dialog or just startActivityForResult. 
     Log.e("Auth", "Recoverable authentication exception: " + recoverableException.getMessage(), recoverableException); 
    } catch (GoogleAuthException authEx) { 
     // This is likely unrecoverable. 
     Log.e("Auth", "Unrecoverable authentication exception: " + authEx.getMessage(), authEx); 
    } catch (IOException ioEx) { 
     Log.i("Auth", "transient error encountered: " + ioEx.getMessage()); 
    } 
    return token; 
} 

回答

0

好吧,所以我終於找到了一些可以幫助你們任何人仍然在努力解決這個問題。

我改變了範圍,像這樣:

"audience:server:client_id:" + clientId 

就是這樣。即使沒有指定「plus.login」作用域,它也可以工作。所以,謝謝。

希望這會有所幫助!