Getting google contacts with javascript

后端 未结 2 1054
野的像风
野的像风 2020-12-16 04:11

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 th

相关标签:
2条回答
  • 2020-12-16 04:57

    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.

    0 讨论(0)
  • 2020-12-16 05:14

    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!

    0 讨论(0)
提交回复
热议问题