2012-08-13 43 views
5

我曾使用2.0版的Contacts API与Gdata库导入客户Gmail信息。这个版本不再支持,我尝试迁移到V3,但我看到G3不支持V3,我花费一天的时间尝试修改当前代码,以使用JavaScript的“Contacts API version 3.0”。如何使用google-api-javascript-client或“Contacts API version 3.0”从Gmail导入联系人?

<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <title>Gmail Login</title> 
     <meta http-equiv="content-type" content="text/html;charset=UTF-8"/> 
     <script type="text/javascript" src="http://www.google.com/jsapi"></script> 
    </head> 
    <body style="margin:0;padding:0;"> 
     <img src="/images/templates.png" style="display:none;"/> 
     <script type="text/javascript"> 
      google.load("gdata", "2.s"); 
      google.setOnLoadCallback(function(){ 
       if(window.location.hash=="") { 
        if(!checkLogin()){ 
         logMeIn(); 
        } else { 
         var feedUrl = "https://www.google.com/m8/feeds/contacts/default/full"; 
         query = new google.gdata.contacts.ContactQuery(feedUrl); 
         query.setMaxResults(5000); 
         myService = new google.gdata.contacts.ContactsService('exampleCo-exampleApp-1.0'); 
         myService.getContactFeed(query, function(result) { 
           document.cookie="g314-scope-0="; 
            window.opener.parseGmailContacts(result.feed.entry); 
          close(); 
          }, function(e){ 
           alert(e.cause ? e.cause.statusText : e.message); 
         }); 
        } 
       } 
      }); 
      function logMeIn() { 
       scope = "https://www.google.com/m8/feeds"; 
       var token = google.accounts.user.login(scope); 
      } 
      function logMeOut() { 
       google.accounts.user.logout(); 
      } 
      function checkLogin(){ 
       scope = "https://www.google.com/m8/feeds/"; 
       var token = google.accounts.user.checkLogin(scope); 
       return token; 
      } 
     </script> 
    </body> 
    </html> 

Google Contacts API 3.0版本支持javascript客户端或gdata库吗?

回答

7
var authParams = gapi.auth.getToken() // from Google oAuth 

authParams.alt = 'json'; 

$.ajax({ 
    url: 'https://www.google.com/m8/feeds/contacts/default/full', 
    dataType: 'jsonp', 
    data: authParams, 
    success: function(data) { console.log(data); } 
}); 

基本上只要插上这在谷歌API提供的authSample.html JavaScript库 - https://code.google.com/p/google-api-javascript-client/

+0

感谢您的回答这个问题,但只要我阅读GAPI库不支持任何更多的权利,我有错误告诉我gapi是未定义的,虽然我包含了相关的JS库 – 2012-09-12 10:01:44

相关问题