jquerygdata-api

How to get auth token to use contct api of google using Javascript and jQuery?


I want to get auth token of google using jQuery. I know there are many predeveloped libraries for this, but I want to this using protocol described in api documentation.


Solution

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