7

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

The authentication is already made, so I need only how to get the contact list. I have read that Google Contacts Api 1 and 2 had some examples for Javascript codes, but i can't find anything on the Google Contacts V3 site. Could it be that this can no more be done?

1
  • You can use external SDKs to get contacts in an easiest way, like cloudsponge.com. It's has an easy SDK for several languages, a widget importer and support a lot of different contact services. Disclaimer: I work for CloudSponge. Commented Aug 15, 2014 at 14:12

2 Answers 2

20

Google Contacts API v3 does not provide a JavaScript SDK.

However, if you want to handle the contact importing on the client-side you can do it with an ajax call :

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 that helps!

Sign up to request clarification or add additional context in comments.

7 Comments

What is clientId and apiKey? How do I get those?
To get those you need to register in the Google Developers Console console.developers.google.com
how can i get google contacts by auth 2.0 ? I have no apiKey.
I suggest to use hello.js - It makes it very easy to start with Google authentication AND contacts.
@Tristan Do we need to pay for getting an account in console.developers.google.com ?
|
1

This is what we found to work to get individual data:

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

If you run JSON.stringify(response) you can see all of the headers that you can call on.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.