本文介绍了使用 javascript 获取谷歌联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Javascript 获取已使用 OAuth 2 进行身份验证的用户的联系人?

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

身份验证已经完成,所以我只需要如何获取联系人列表.我读过 Google Contacts Api 1 和 2 有一些 Javascript 代码示例,但我在 Google Contacts V3 站点上找不到任何内容.莫非这已经不行了?

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?

推荐答案

Google Contacts API v3 不提供 JavaScript SDK.

Google Contacts API v3 does not provide a JavaScript SDK.

但是,如果您想在客户端处理联系人导入,您可以使用 ajax 调用来完成:

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

希望有帮助!

这篇关于使用 javascript 获取谷歌联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 11:51