问题
I have this problem, that usually api entry point works fine:
https://www.google.com/analytics/feeds/accounts/default
but when I add parameters like:
https://www.google.com/analytics/feeds/accounts/default?max-results=50
then it fails. This is the part of the interaction if someone can tells whats wrong:
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
This is asked several times over here and there with different variations, but I cant find the underlying problem solved so far...
回答1:
It turns out, that Google requires url params on signature base string:
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
->
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&max-results=50
In alphabetical order of course as all other params should be too. This fixed my problem.
来源:https://stackoverflow.com/questions/8099880/google-api-with-params-gives-unknown-authorization-header