开发者

ClientLogin from Google API doesn't works with AJAX

开发者 https://www.devze.com 2022-12-18 13:33 出处:网络
I\'m trying to login to a Google Account for request Picassa Web photos with AJAX. That\'s t开发者_如何学Pythonhe code:

I'm trying to login to a Google Account for request Picassa Web photos with AJAX. That's t开发者_如何学Pythonhe code:

xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST","https://www.google.com/accounts/Login",true);
xmlhttp.send("accountType=HOSTED_OR_GOOGLE&Email=...&Passwd=...&service=lh2&source=prova");
document.getElementById('prova').innerHTML=xmlhttp.responseText;

With this firebug shows a 200 OK status in the Net tab but an unexplained error in the Console. Of course nothing appears in the div called "prova" since answer is empty.

I also try to add this header:

xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

But then firebug shows a 400 Bad Request in the Net tab. Can you help me? Thank you.


You should be able to view the ajax reponse in firebug and see what is gtting posted back to you - you can get a 200 error but still get an error in the post back. Don't you need to do something with an AuthToken too?


Solved! Firefox and new browsers don't let make AJAX call to third-party applications for security reasons. All is explained here: http://www.xml.com/pub/a/2005/11/09/fixing-ajax-xmlhttprequest-considered-harmful.html


Wasn't sure if we got the authToken or not...

Here's how I've been making xDomain Posts:

It requires having a little library (tiny) called flyJSONP, which uses YQL (Yahoo! Query Language) as a JSONP hack. Works great, but cannot post/get headers. After, I send data to php which then makes a cross-domain post with necessary header.

FlyJSONP also works with get... FlyJSONP.get({...

    FlyJSONP.post({
        url: "https://www.google.com/accounts/ClientLogin",
        parameters: {
            name: "value"
        },
        success: function(data) {
            console.log("the response is: " + data);
        },
        error: function(errorMsg) {
            console.log(errorMsg);
        },
        complete: function(data){
            console.log("...completed post!");
        }
    });
0

精彩评论

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

关注公众号