【发布时间】: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