2012-08-13 7 views
5

Ich wurde 2.0 Version der Kontakte API mit Gdata Bibliothek verwendet, um Kunden Gmail Informationen zu importieren. Diese Version wird nicht mehr unterstützt und ich versuche nach V3 zu wechseln, aber ich sehe, dass Gdata nicht mit v3 unterstützt wird und ich verbringe den Tag damit, zu versuchen, den aktuellen Code so zu modifizieren, dass er mit "Contacts API Version 3.0" für Javascript funktioniert.Wie kann ich Kontakte aus Google Mail mit Google-API-Javascript-Client oder "Contacts API Version 3.0" importieren?

<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 Kontakte API Version 3.0 unterstützt JavaScript-Client oder Gdata-Bibliothek?

Antwort

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); } 
}); 

Im Grunde nur diese Stecker in der authSample.html in dem Google-API zur Verfügung gestellt JavaScript-Bibliothek - https://code.google.com/p/google-api-javascript-client/

+0

Danke, diese Frage zu beantworten, aber wie ich gapi Bibliothek nicht unterstützen lese mehr richtig und ich hatte error Erzähl mir, dass gapi undefiniert ist, obwohl ich eine verwandte JS-Bibliothek einschließe –