【问题标题】:Unknown authorization header - Error 401未知的授权标头 - 错误 401
【发布时间】:2011-06-23 23:04:20
【问题描述】:

我正在使用 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)

这有什么问题?

【问题讨论】:

    标签: java oauth request-headers


    【解决方案1】:

    Android Google Calendar Authorization Problem。谷歌正在对日历提要做一些不同的事情,在查询字符串中使用新的“gsessionid”参数进行重定向;电子表格可能是同样的问题。

    【讨论】:

      【解决方案2】:

      我怀疑服务器正在发送带有 WWW-Authenticate 标头的“401 Unauthorized”响应,客户端代码无法识别该标头。它甚至可能根本没有发送 WWW-Authenticate 标头...视频异常消息中的“null”。

      (后者违反了 HTTP 1.1 规范。要求有一个 401 响应有一个 WWW-Authenticate 标头,客户端使用该标头来决定 如何 进行身份验证. 详情请参阅规范。)


      那么,为什么在与 Google 供稿对话时会发生这种情况?也许您为客户端配置了错误的 URL?也许您的客户正在尝试通过一些设计不佳的代理进行连接?

      【讨论】:

      • 按照这里指定的:checkupdown.com/status/E401.html,我已经授权客户并且我也登录了。
      • 由于我已在 GAE 上在线注册了此应用程序,因此不可能再次出现错误的 URL!甚至我指定的范围和提要 URL 也是正确且有效的!
      • 好吧,我很难过。也许您应该使用 wireshark 或类似的东西来查看 HTTP 请求和响应真正包含的内容。您可以做的另一件事是在 Google 搜索结果中查找此错误。
      • 哦!令人惊讶的是,从一个完整的新项目中,它可以工作!但是,这里的访问令牌从一开始就在会话中。在此应用程序中,我从 Google Datastore 获取访问令牌,该令牌之前存储!
      • Google Jump 目前仍未解决的另一个问题是:stackoverflow.com/questions/4921523/…
      猜你喜欢
      • 2012-04-04
      • 2017-11-23
      • 1970-01-01
      • 2013-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-07
      相关资源
      最近更新 更多