【发布时间】:2012-09-28 13:17:32
【问题描述】:
在 oauth2 舞蹈的第 1 步之后,我可以在重定向 URL 中检索代码。这工作正常。但是,
我遇到了“com.google.api.client.http.HttpResponseException: 400 Bad Request”错误
试图获取 accessTokenResponse。知道为什么吗?
AuthorizationCodeGrant request = new AuthorizationCodeGrant(new NetHttpTransport(),
new JacksonFactory(),
OAuth2ClientCredentials.ACCESS_TOKEN_URL,
OAuth2ClientCredentials.CLIENT_ID,
OAuth2ClientCredentials.CLIENT_SECRET,
code,
OAuth2ClientCredentials.REDIRECT_URI);
try {
AccessTokenResponse accessTokenResponse = request.execute();
CredentialStore credentialStore = new SharedPreferencesCredentialStore(prefs);
credentialStore.write(accessTokenResponse );
} catch (IOException e) {
Log.e(TAG, "error= "+e);
e.printStackTrace();
}
这是触发错误的行:
AccessTokenResponse accessTokenResponse = request.execute();
我正在使用“com.google.api.client.auth.oauth2.draft10.AccessTokenRequest.AuthorizationCodeGrant”
我应该使用其他东西吗?有什么建议吗?
【问题讨论】:
-
您可以尝试使用返回的代码手动请求授权令牌,看看是否可行。有关示例,请参见 stocktwits.com/developers/docs/api#oauth-token-docs。
标签: android oauth-2.0 stocktwits