【问题标题】:Make GoogleAuthUtil stop asking user for offline access让 GoogleAuthUtil 停止询问用户离线访问
【发布时间】:2014-12-27 22:27:20
【问题描述】:

我正在尝试为我的后端开发一个具有客户端 Google oAuth2.0 授权的应用程序。我已经在 Google 开发者控制台上完成了所有需要的工作。 每当应用使用GoogleAuthUtil.getToken() 请求授权令牌时,Google 都会不断要求离线访问。我想一劳永逸地授予权限,因此授权过程变得无声。

这是我在授权中使用的代码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;
}

【问题讨论】:

    标签: android google-app-engine google-oauth


    【解决方案1】:

    好的,所以我终于找到了一些可以帮助仍在为这个问题苦苦挣扎的任何人的东西。

    我将范围更改为这样的:

    "audience:server:client_id:" + clientId
    

    就是这样。即使没有指定“plus.login”范围,它也可以工作。

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-03
      • 2014-03-06
      • 1970-01-01
      • 2014-07-01
      相关资源
      最近更新 更多