我正在尝试通过 Android 上的 API 访问 goo.gl URLShortener。我正在使用 AccountManager 生成访问令牌:
String authTokenType = "oauth2:https://www.googleapis.com/auth/urlshortener";
String authToken = this.prefs.getString(Key.PREF_GOOGLE_ACCESS_TOKEN, "null");
if (!"null".equals(authToken)) {
accountManager.invalidateAuthToken(authTokenType, authToken);
}
//(...)
accountManager.getAuthToken(account, authTokenType, false, new GetAuthTokenCallback(), null);
当我GetAuthTokenCallback
使用生成的身份验证令牌运行 HTTP 请求以接收 URL 历史记录时,我得到状态401:unauthorized
:
HttpGet http_get = new HttpGet("https://www.googleapis.com/urlshortener/v1/url/history");
http_get.addHeader("Authorization", tokens[0]);
HttpResponse response;
response = GoogleOAuthOnPreferenceChangeListener.this.http_client.execute(http_get);
Log.d("tag", "Status: (" + response.getStatusLine().getStatusCode() + ") " + response.getStatusLine().getReasonPhrase());
JSON-Response 的内容是
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
我有