【问题标题】:Is there any way to get Google Auth Token, without taking user's permission android有没有什么方法可以在没有用户许可的情况下获取 Google Auth Token android
【发布时间】:2017-10-22 21:39:40
【问题描述】:

我想使用以下方法取出用户的 GoogleAuthToken:

私有类 RetrieveTokenTask 扩展 AsyncTask {

    @Override
    protected String doInBackground(String... params) {
        String accountName = params[0];
        String scopes = "oauth2:openid";
        String token = null;
        try {
            token = GoogleAuthUtil.getToken(getApplicationContext(), accountName, scopes);
        } catch (IOException e) {
            Log.e(TAG, e.getMessage());
        } catch (UserRecoverableAuthException e) {
            Log.e(TAG, e.getMessage());
            startActivityForResult(e.getIntent(), REQ_SIGN_IN_REQUIRED);
        } catch (GoogleAuthException e) {
            Log.e(TAG, e.getMessage());
        }
        return token;
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);

        if (s != null) {
            Log.e("AccessToken", s);
            preferences.edit().putString(PreferencesConstants.GOOGLE_AUTH_TOKEN, s).commit();
        }
    }
}

注意:此方法成功地给了我令牌,但问题是:它第一次要求用户的允许和拒绝权限。 (我不想要)。有什么方法可以在未经用户许可的情况下取出令牌。 ?

【问题讨论】:

    标签: android google-authentication


    【解决方案1】:

    这是由于授予应用程序的 API 访问权限。对于每台开发人员机器,应将 SHA1 提供给 API,并为每个 SHA1 创建单独的 Android API 密钥。

    转到 console.developers.google.com -> 选择您的项目 API & AUTH -> 凭证。 创建新的客户端密钥(尽管它有其他客户端密钥)。 选择已安装的应用程序-> android。 给你的包名和SHA1正确选择OK。

    【讨论】:

      猜你喜欢
      • 2018-12-25
      • 2017-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-16
      相关资源
      最近更新 更多