如何使用Javascript和jQuery获取auth令牌使用谷歌的conct api?

时间:2011-08-30 13:26:14

标签: jquery gdata-api

我想使用jQuery获取谷歌的身份验证令牌。我知道有很多预先开发的库,但我想使用api文档中描述的协议。

1 个答案:

答案 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...!!");
     }
   });  
 }