2011-11-11 86 views
2

我有這個問題,通常API入口點工作正常:使用參數谷歌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%3D44173%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="44173", 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 

這幾次詢問在這裏和那裏有不同的變化,但我不能找到迄今爲止解決根本問題...

+0

我有完全相同的問題。非常沮喪。對我來說,問題在於帶有PUT請求的Google日曆API。它僅在將v = 2或gsessionid參數附加到url時發生。 – Melvin

+0

請參閱下面的答案。基本字符串和發佈的值需要完全匹配,這是我的情況至少是問題。 – MarkokraM

回答

1

事實證明,谷歌認爲需要對簽名基本字符串網址參數:

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%3D4 4173%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%3D44173%26oauth_token%3DCONSUMERTOKEN%26oauth_version%3D1.0 &最大結果= 50

當然,在按字母順序排列的所有其他PARAMS應該太。這解決了我的問題。

+0

所以你發送它在標題而不是網址? – Melvin