Getting google contacts with javascript

How can I get the contacts of a user who has already authenticated with OAuth 2 using Javascript?

Authentication has already been completed, so I only need to get a list of contacts. I read that there are some examples for Javascript codes in Google Contacts Api 1 and 2, but I can not find anything on the Google Contacts V3 website. Maybe this can no longer be done?

+7
javascript google-oauth google-contacts
source share
2 answers

The Google v3 Contact API does not provide a JavaScript SDK.

However, if you want to handle importing contacts on the client side, you can do this by calling ajax:

var clientId = 'XXX'; var apiKey = 'XXX'; var scopes = 'https://www.google.com/m8/feeds'; $(document).on('click', '.js-google_contacts', function() { gapi.client.setApiKey(apiKey); window.setTimeout(checkAuth, 3); }); function checkAuth() { gapi.auth.authorize({ client_id: clientId, scope: scopes, immediate: false }, handleAuthResult); } function handleAuthResult(authResult) { if (authResult && !authResult.error) { $.get('https://www.google.com/m8/feeds/contacts/default/full?alt=json&access_token=' + authResult.access_token + '&max-results=700&v=3.0', function(response) { //Handle Response }); } } 

Hope this helps!

+19
source share

This is what we found to work with individual data:

 var response = (JSON.stringify(response.feed.entry[0].gd$email, null, 4)); console.log(response); 

If you run JSON.stringify (response), you will see all the headers you can call.

+1
source share

All Articles