通过javascript获取谷歌联系人 [英] Getting google contacts with javascript

查看:195
本文介绍了通过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获取谷歌联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆