我想使用jQuery获取谷歌的身份验证令牌。我知道有很多预先开发的库,但我想使用api文档中描述的协议。
答案 0 :(得分:1)
尝试以下代码..
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...!!");
}
});
}