带有params的google api会给出未知的授权标题

时间:2011-11-11 20:58:15

标签: google-analytics google-api gdata

我有这个问题,通常api入口点工作正常:

https://www.google.com/analytics/feeds/accounts/default

但是当我添加如下参数时:

https://www.google.com/analytics/feeds/accounts/default?max-results=50

然后失败了。如果有人能说错了,这就是互动的一部分:

GET&https%3A%2F%2Fwww.google.com%2Fanalytics%2Ffeeds%2Faccounts%2Fdefault&oauth_consumer_key%3DCONSUMERKEY%26oauth_nonce%3D88526211463343710%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1321044173%26oauth_token%3DCONSUMERTOKEN%26oauth_version%3D1.0
{ host: 'www.google.com',
  path: '/analytics/feeds/accounts/default?max-results=25',
  method: 'GET',
  headers: { Authorization: 'OAuth oauth_token="CONSUMERTOKEN", oauth_timestamp="1321044173", oauth_nonce="88526211463343710", oauth_consumer_key="CONSUMERKEY", oauth_signature_method="HMAC-SHA1", oauth_version="1.0", oauth_signature="S%2Bob3FyVFpwRsu4x7C%2FwmkwbnDY%3D"' } }
STATUS: 401
HEADERS: {"www-authenticate":"GoogleLogin realm=\"http://www.google.com/accounts/ClientLogin\", service=\"analytics\"","content-type":"text/html; charset=UTF-8","date":"Fri, 11 Nov 2011 20:42:56 GMT","expires":"Fri, 11 Nov 2011 20:42:56 GMT","cache-control":"private, max-age=0","x-content-type-options":"nosniff","x-frame-options":"SAMEORIGIN","x-xss-protection":"1; mode=block","server":"GSE","connection":"close"}
response: Unknown authorization header

在这里和那里有几次不同的变化要求,但我找不到到目前为止解决的潜在问题......

1 个答案:

答案 0 :(得分:1)

事实证明,Google需要在签名基础字符串上使用url params:

GET&安培; HTTPS%3A%2F%2Fwww.google.com%2Fanalytics%2Ffeeds%2Faccounts%2Fdefault&安培; oauth_consumer_key%3DCONSUMERKEY%26oauth_nonce%3D88526211463343710%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1321044173%26oauth_token%3DCONSUMERTOKEN%26oauth_version%3D1 0.0

- >

GET&安培; HTTPS%3A%2F%2Fwww.google.com%2Fanalytics%2Ffeeds%2Faccounts%2Fdefault&安培; oauth_consumer_key%3DCONSUMERKEY%26oauth_nonce%3D88526211463343710%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1321044173%26oauth_token%3DCONSUMERTOKEN%26oauth_version%3D1 0.0&安培;最大结果= 50

当然,按字母顺序排列,所有其他参数也应如此。这解决了我的问题。