I want to get auth token of google using jQuery. I k开发者_运维技巧now there are many predeveloped libraries for this, but I want to this using protocol described in api documentation.
try the following code..
function clientlog(Adminemail,adminpass) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
$.ajax({
type: 'POST',
url: 'https://www.google.com/accounts/ClientLogin',
contentType: 'application/x-www-form-urlencoded',
data: { accountType : "HOSTED", Email : ""+Adminemail+"", Passwd : ""+adminpass+"", service : "cp"}, // cp for contact service..
success: function (response) {
var tokenArray = response.split("="); // Split to response tokenArray[3] is the auth token
token = tokenArray[3];
token= token.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
alert("Done");
$("#lable").html("you have logged in successfully..!!");
$("#uname").val("");
$("#pass").val("");
$("#login").attr("disabled","disabled")
},
error: function(){
$("#lable").html("Sorry Error in Login...!!");
}
});
}
精彩评论