Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i import contacts from gmail using google-api-javascript-client or "Contacts API version 3.0"?

I was used 2.0 version of Contacts API with Gdata library to import customer gmail information. This version not supported anymore and I try to move to V3 but I see the Gdata not supported with v3 and I spend dayes try to modify current code to work with "Contacts API version 3.0" for javascript.

    <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 version 3.0 supported javascript client or gdata library?

like image 932
Khadijah J Shtayat Avatar asked Aug 13 '12 10:08

Khadijah J Shtayat


1 Answers

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

Basically just plug this in to the authSample.html provided in the google api javascript library -- https://code.google.com/p/google-api-javascript-client/

like image 188
sucitivel Avatar answered Sep 20 '22 17:09

sucitivel