This is the continue of my previous question:
Delphi, WebBrowser, Google Login, FusionTable
But the test with WinHTTP also failed as TWebBrowser based test...
And this is one question as you wish... :-)
I have one table what is NOW PUBLIC, but when we will buy non-free account it will be changed to private kind.
I created a simple WinHTTP test, but this also failed.
I can login, I got the "Auth" tag, but the next "private" request returns 401 error.
procedure TForm1.BitBtn1Click(Sender: TObject);
var
WinHttpReq, temp : variant;
URL, s : String;
params : TStringList;
authtoken, query, posts : string;
begin
URL := 'https://www.google.com/accounts/ClientLogin';
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
params := TStringList.Create;
try
params.Values['accountType'] := 'GOOGLE';
params.Values['Email'] := csEmail;
params.Values['Passwd'] := csPwd;
params.Values['service'] := 'fusiontables';
params.Values['source'] := csSource;
posts := EncodeParamsToURL(params);
finally
params.Free;
end;
URL := URL + '?' + posts;
WinHttpReq.Open('POST', URL, false);
WinHttpReq.Send();
s := WinHttpReq.ResponseText;
Memo1.Lines.Text := s;
params := TStringList.Create;
try
params.Text := s;
authtoken := params.Values['Auth'];
Edit1.Text := authtoken;
finally
params.Free;
end;
//query := URLEncode('SHOW TABLES');
query := URLEncode('select * from 1236965');
url := 'http://www.google.com/fusiontables/api/query?sql=' + query;
WinHttpReq.Open('POST', URL, false);
WinHttpReq.setRequestHeader('Authorization', 'GoogleLogin auth="' + authToken + '"');
WinHttpReq.Send();
s := WinHttpReq.ResponseText;
Memo1.Lines.Text := s;
end;
When I made "select", I got the rows. But when I want to see the tablenames, I get 401 error...
I'm not sure what cause this error.
a. The free account don't have enough rights to access it privately
b. I set the header wrong
c. I set the csSource wrong (I set it "MyCompanyName-Test-1.0")
d. Other thing I don't know what...
Can anybody help me how to login and access the data successfully?
Change your method to GET:
WinHttpReq.Open('GET', URL, false);
And remove the " around your auth token:
WinHttpReq.setRequestHeader('Authorization', 'GoogleLogin auth=' + authToken);
The first change is to comply with the documentation (although POST also works). The second change fixes the error.