我正在使用 HMAC-SH1 符号访问 Google 电子表格供稿。我的代码是:
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
oauthParameters.setScope("https://spreadsheets.google.com/feeds/");
oauthParameters.setOAuthType(OAuthParameters.OAuthType.THREE_LEGGED_OAUTH);
oauthParameters.setOAuthToken(request.getSession().getAttribute("oauth_token").toString());
oauthParameters.setOAuthTokenSecret(request.getSession().getAttribute("oauth_token_secret").toString());
GoogleService googleService = new GoogleService("wise", "searceapps-searcegadget2-1");
googleService.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
URL feedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full/");
SpreadsheetFeed resultFeed = googleService.getFeed(feedUrl, SpreadsheetFeed.class);
但是,我收到错误:
Oauth.requestServlet doGet: null com.google.gdata.util.AuthenticationException: OK Unknown authorization header
Unknown authorization header
Error 401
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600) at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563) at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552) at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530) at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535) at com.google.gdata.client.Service.getFeed(Service.java:1135) at com.google.gdata.client.Service.getFeed(Service.java:998) at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631) at com.google.gdata.client.Service.getFeed(Service.java:1017) at Oauth.accessFeeds.access(accessFeeds.java:74)
这有什么问题吗?
最佳答案
我怀疑服务器正在发送带有 WWW-Authenticate 的“401 Unauthorized”响应客户端代码无法识别的 header 。它甚至可能根本不发送 WWW-Authenticate header ...见异常消息中的“null”。
(后者违反了 HTTP 1.1 规范。需要 401 响应才能拥有 WWW-Authenticate header ,客户端使用该 header 来决定如何进行身份验证. 详细信息请参阅规范。)
<小时/>那么为什么在与 Google Feed 对话时会发生这种情况呢?也许您使用了错误的 URL 配置了客户端?也许您的客户端正在尝试通过一些设计不良的代理进行连接?
关于java - 未知的授权 header - 错误 401,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4942324/