未知的授权标头 - 错误 401
我正在使用 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: 确定 未知 授权标头
未知 授权标头
错误 401
在 com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600) 在 com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563) 在 com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552) 在 com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530) 在 com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535) 在 com.google.gdata.client.Service.getFeed(Service.java:1135) 在 com.google.gdata.client.Service.getFeed(Service.java:998) 在 com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631) 在 com.google.gdata.client.Service.getFeed(Service.java:1017) 在 Oauth.accessFeeds.access(accessFeeds.java:74)
这有什么问题?
I am accessing Google Spreadsheet feeds using HMAC-SH1 sign. My Code is :
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);
But, I am getting the error :
Oauth.requestServlet doGet: null
com.google.gdata.util.AuthenticationException:
OK Unknown
authorization headerUnknown
authorization headerError
401at
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)
What is the problem with this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑服务器正在发送带有 的“401 Unauthorized”响应客户端代码无法识别的 WWW-Authenticate 标头。它甚至可能根本不发送 WWW-Authenticate 标头...见异常消息中的“null”。
(后者违反了 HTTP 1.1 规范。需要 401 响应才能拥有 WWW-Authenticate 标头,客户端使用该标头来决定如何进行身份验证。请参阅详细信息请参阅规范。)
那么,为什么与 Google feed 对话时会发生这种情况呢?也许您使用了错误的 URL 配置了客户端?也许您的客户端正在尝试通过一些设计不良的代理进行连接?
I suspect that the server is sending a "401 Unauthorized" response with a WWW-Authenticate header that the client code doesn't recognize. It may even be sending no WWW-Authenticate header at all ... vide the "null" in the exception message.
(The latter is a violation of the HTTP 1.1 specification. A 401 response is required to have a WWW-Authenticate header that the client uses to decide how to authenticate. Refer to the spec for details.)
So why might this be happening talking to a Google feed? Perhaps you've configured your client with the wrong URL? Perhaps your client is trying to connect via some poorly designed proxy?
请参阅 Android Google 日历授权问题。谷歌正在对日历提要做一些不同的事情,在查询字符串中使用新的“gsessionid”参数进行重定向;电子表格可能有同样的问题。
See Android Google Calendar Authorization Problem. Google is doing something different with the calendar feeds, redirecting with a new 'gsessionid' parameter in the querystring; may be the same problem with spreadsheet.