Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
765 views
in Technique[技术] by (71.8m points)

oauth 2.0 - Getting google contacts with javascript

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...