Google アナリティクス API からフィードを取得しようとすると、このエラーが発生します。ただし、同じトークンを使用すると、Google カレンダーから正常なフィードを取得できます。2 つの間のコードは、フィード URL を除いてまったく同じです。したがって、Analytics が https で、Calendar が http であることに関係があるはずです。
非セキュアで有効期間の長いトークンの作成に成功しました。初期トークンをリクエストする際のスコープ パラメータ:
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)
有効期間の長いトークンを返します。Google カレンダーでの使用:
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 が成功します。
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
しかし、Google アナリティクス フィードを取得しようとすると、エラー 401 が表示されます。
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 の Delphi 2007 で Indy10 を使用します。
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