嘗試從Google Analytics API獲取饋送時出現此錯誤。不過,使用相同的標記,我會從Google日曆獲取成功的Feed。兩者之間的代碼除了提供網址之外完全相同。因此,它必須與Google Analytics(分析)爲https和Calendar(日曆)有關。HTTP/1.1 401令牌無效 - AuthSub令牌有錯誤的範圍
我已經成功創建了一個不安全的長期令牌。同時要求初始令牌範圍參數:
scope=http%3A%2F%2Fwww.google.com%2Fcalendar%2Ffeeds%2F%20https%3A%2F%2Fwww.google.com%2Fanalytics%2Ffeeds
我對長期令牌請求:
GET /accounts/AuthSubSessionToken HTTP/1.1
Authorization: AuthSub token="CP_AgsyLDxDCtpjg-f____8B"
Content-Type: application/x-www-form-urlencoded
Host: www.google.com:443
Accept: text/html, */*
Accept-Encoding: identity
User-Agent: Mozilla/3.0 (compatible; Indy Library)
返回一個長期令牌。使用它的谷歌日曆:
GET /calendar/feeds/default/allcalendars/full HTTP/1.1
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Authorization: AuthSub token="CP_AgsyLDxCh2tmj-P____8B"
Host: www.google.com
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Accept-Encoding: identity
User-Agent: Mozilla/3.0 (compatible; Indy Library)
返回臨時重定向(302):
HTTP/1.1 302 Moved Temporarily
Expires: Sun, 01 Nov 2009 03:00:01 GMT
Date: Sun, 01 Nov 2009 03:00:01 GMT
Set-Cookie: S=calendar=mta4-_BxxANrylcSnzUatg;Expires=Mon, 01-Nov-2010 03:00:01 GMT
Location: http://www.google.com/calendar/feeds/default/allcalendars/full?gsessionid=mta4-_BxxANrylcSnzUatg
導致一個成功的得到這個:
GET /calendar/feeds/default/allcalendars/full?gsessionid=mta4-_BxxANrylcSnzUatg HTTP/1.1
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Authorization: AuthSub token="CP_AgsyLDxCh2tmj-P____8B"
Host: www.google.com
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Accept-Encoding: identity
User-Agent: Mozilla/3.0 (compatible; Indy Library)
Cookie: S=calendar=mta4-_BxxANrylcSnzUatg
但我得到的錯誤401試圖獲取Google Analytics Feed時:
GET /analytics/feeds/accounts/default HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: AuthSub token="CP_AgsyLDxCh2tmj-P____8B"
Host: www.google.com:443
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Accept-Encoding: identity
User-Agent: Mozilla/3.0 (compatible; Indy Library)
我的域名需要有效的SSL證書嗎?一直在爭取這個星期!
在Apache中使用Indy10和Delphi 2007。
請求提供一些Delphi代碼。我在這裏提供的是用於GET的代碼。我不提供代碼來獲取令牌,因爲我認爲它們很好(我可以獲取日曆提要)。
var
IdHTTP: TIdHTTP;
IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocketOpenSSL;
begin
IdSSLIOHandlerSocket1 := TIdSSLIOHandlerSocketOpenSSL.create(nil);
IdHTTP := TIdHTTP.create(nil);
with IdSSLIOHandlerSocket1 do begin
SSLOptions.Method := sslvSSLv3;
SSLOptions.Mode := sslmUnassigned;
SSLOptions.VerifyMode := [];
SSLOptions.VerifyDepth := 2;
end;
with IdHTTP do begin
IOHandler := IdSSLIOHandlerSocket1;
ProxyParams.BasicAuthentication := False;
Request.UserAgent := 'Mozilla/3.0 (compatible; Indy Library)';
Request.ContentType := 'application/x-www-form-urlencoded';
request.host := 'www.google.com/analytics';
request.connection := 'keep-alive';
Request.Accept := 'text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2';
end;
idhttp.Request.CustomHeaders.Add('Authorization: AuthSub token="'+mToken+'" ');
IdHTTP.Get('https://www.google.com/analytics/feeds/accounts/default'); // results in the 401
show是你的一些Delphi代碼,尤其是你如何做HTTPS處理 – 2009-11-01 08:08:11
請將用戶代理設置爲代表* your *程序的字符串。使用通用值可以讓您的程序與其他沒有專門研究的人混在一起,這可能會導致服務器過濾您的程序,認爲這只是另一個DoS攻擊。 – 2009-11-01 20:36:23
我嘗試將用戶代理設置爲獨特的: 用戶代理:測試Google Analytics界面 仍然是同樣的問題。 – 2009-11-02 01:18:33