开发者

Delphi, WebBrowser, Google Login, FusionTable

I check a possibility to integrate fusiontables into my Delphi TWebBrowser based application.

But I cannot continue my project because I don't understand many things.

I have a public table, I want to access this, upload some rows, update some rows, and show it with fusiontablelayer. I have only "free" account now.

The problems:

1.)

I need to authenticate.

var
    posts, s, url : string;
    authToken : string;
    postdata,
    header : OleVariant;
    params : TStringList;
    i : integer;
begin
    header := 'Content-type: application/x-www-form-urlencoded'#13#10;

    params := TStringList.Create;
    try
        params.Values['accountType'] := 'GOOGLE';
        params.Values['Email'] := 'any';
        params.Values['Passwd'] := 'any';
        params.Values['service'] := 'fusiontables';
        params.Values['source'] := '?'; // WHAT IS THIS?
        posts := EncodeParamsToURL(params);
    finally
        params.Free;
    end;

    postdata := VarArrayCreate([0, Length(posts) - 1], varByte);

    // Put Post in array
    for i := 1 to Length(posts) do
        postdata[I - 1] := Ord(posts[I]);

    url := 'https://www.google.com/accounts/ClientLogin';
    wb.Navigate(url, emptyparam, emptyparam, postdata, header);

    while wb.ReadyState <> READYSTATE_COMPLETE do
        Application.ProcessMessages;

    s := (wb.Document as iHTMLDocument2).body.innerText;

This is only a demo, but it is working. I don't know what is "SOURCE" parameter, but I got three lines as result, and the last is "Auth=...." that containing the token.

http://code.google.com/intl/hu-HU/apis/fusiontables/docs/samples/apps_script.html

2.)

I need to push this token into header. When I do this, I got 401 error.

params := TStringList.Create;
try
    params.Text := s;
    authToken := params.Values['Auth'];
finally
    params.Free;
end;


header := 'Authorization : GoogleLogin auth="' + authToken + '"'#13#10;

url := 'http://www.google.com/fusiontables/api/query?select * from 1236944';

wb.Navigate(url, emptyparam, emptyparam, emptyparam, header);

So I'm totally confused now.

First:

Because JavaScript layer don't have authentication interface, I think I need to authenticate the "browser". May this is is wrong idea, but my thinking based on common web login logic, where the login creates a Session, and the Session is identified as a hidden cookie what is valid in this browser. But may Google login is uses an identifier what passed on every request... I don't know.

So because this I must do an automatic "login" in the browser. (If that is not true then I can use WinInet, or IdHTTP for login, and use only the token in the browser).

Now I don't have idea how to do this login automatically without show the login name/pwd in the html, or show the token result in the TWebBrowser...

Second:

I must modify the data. This may realizable in a transparent component, like idHTTP, and I can show only the changes in the WebBrowser...

Third:

I can show the fusion table with a layer. This is not too hard if I has been authenticated once...

So: I'm confused now, because Google supports only Python/Java as client library, and not Delphi. I need to integrate the authentication and visualization into my TWebBrowser component very transparently.

But there is no g开发者_开发技巧ood example or source in the net what demonstrate the login + fusiontable manipulation...

Can anybody help me in this question?


Question 1 is answered in section "The ClientLogin interface":

Source:

Short string identifying your application, for logging purposes. This string should take the form: "companyName-applicationName-versionID".

Question 2:

Your URL is wrong, it has to be:

url := 'http://www.google.com/fusiontables/api/query?sql=select * from 1236944';

See the "sql=" -part? That's important. Have a look here for an example.

Regarding your other questions: they are a bit confusing. I think you don't have to use the TWebBrowser and can use anything that can issue GET and POST requests. For the login part: this information should be provided by your user, because your application should empower your users to work with their data, right?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜