views:

1074

answers:

3

I am trying to learn the ClientLogin Interface detailed on the Account Authentication APIs on Google code website.

I am using Firefox 3.5pre (Shiretoko) and XMLHttpRequest object in Javascript to follow the process. Here's a stripped down version of what I have:

<html>
<head>
<title>Test</title>
<script type="text/javascript">
  //<![CDATA[
function update() {
  var auth_params = "accountType=HOSTED_OR_GOOGLE&Email=val"
                    +"&passwd=val&service=cl&source=MMA-Learning";
  var request = new XMLHttpRequest();

  request.open('POST', 'https://www.google.com/accounts/ClientLogin', true);

  request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  request.setRequestHeader("Content-Length", auth_params.length);
  request.setRequestHeader("Connection", "close");

  request.onreadystatechange = function () {
    if (this.readyState == 4 && this.status == 200) {
      alert ("Request done");
    }
  };

  try {
    request.send( auth_params );
  } catch (e) {
    alert ("Send Exception:\n"+e);
  }
}
  //]]>
</script>
</head>
<body>
  <a href="javascript:update()">Authenticate</a>
</body>
</html>

When I click on the Authenticate link, all I get back is a Bad Request response. Examining the request headers, I don't see Content-Type set to application/x-www-form-urlencoded.

I am using Firebug 1.5X to examine the traffic.

For now, all I want to do is generate request mentioned in the Sample Request section and get a response mentioned in the Sample Responses section. If I get there, I want to get some account specific data like, unread Google Reader feeds etc.

A: 

Hi maheshasolkar,

I am also having difficulty with clientLogin,

Any chance of you posting your solution to the above problem. It would be a great help, more than you could ever imagine, well maybe you could because you have posted about this and obivously went through the tearing out your hair stage where i am at now :(

It would be so much help!!!!!!!!!!!!!!!!!!!!!!

Hope to hear from you soon, please save me :(

IrishStack

A: 

the 'p' in 'passwd' is a small 'p' instead of a capital 'P'

you probably figured that out tho. When you post and you find the answer, it is always polite if you post the answer as well. This helps the people in the future who will look at your post for information

That 'p' took me two hours to find because i persummed that the code google gave was copied correctely and there was no case mistakes

no point in Internet being full of questions with no answers

A: 

I suspect that you've been bitten by Javascript's "same origin" policy. It prevents Javascript, including XmlHttpRequest, from accessing one domain from another. More information is available from Mozilla.

There are hacks to get around this, but I have no idea if they'll work with Google's API.

David Alan Hjelle