如何获得Gmail联系人使用JavaScript? [英] How do I get Gmail contacts using JavaScript?

查看:208
本文介绍了如何获得Gmail联系人使用JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是Ajax调用,我应该使用JavaScript来获取Gmail联系人?我已经有用户的OAuth令牌,我得到了,因为用户签约使​​用谷歌自己的网站。

解决方案

如果您使用的是OAuth2通过JavaScript,您可以使用谷歌联系人API,但你需要通过发送权限的正确的范围,以获得授权谷歌获得访问令牌,这是 https://www.google.com/m8/feeds 时。 (<一href="https://developers.google.com/google-apps/contacts/v3/index#authorizing_requests_to_the_api_name_service"相对=nofollow>引用)

正如你已经知道如何获得访问令牌,它是简单地调用了正确的查询API。想为你的用户的所有联系人,这是简单,只要做一个异步请求,以获得所需的信息的API。例如,在 {USEREMAIL} 是用户的电子邮件和 {accessToken} 是访问令牌,只要做一个 GET 地址以下URI:

<$p$p><$c$c>https://www.google.com/m8/feeds/contacts/{userEmail}/full?access_token={accessToken}&alt=json

有疑问,你可以发送和它们的参数的类型的列表可以在这里找到:

What is the Ajax call that I should make to get gmail contacts using JavaScript? I already have the user OAuth Token which I got because the user signed up to my site using Google.

解决方案

If you're using OAuth2 through JavaScript, you can use the Google Contacts API, but you'll need to get authorisation by sending the correct scope of permissions to Google when getting the access token, which is https://www.google.com/m8/feeds. (reference)

As you already know how to get the access token, it's as simple as calling the API with the correct query. To get all contacts for your user, it's as simple as making an asynchronous request to the API for the required info. For example, where {userEmail} is the user's email and {accessToken} is your access token, simply make a GET address to the following URI:

https://www.google.com/m8/feeds/contacts/{userEmail}/full?access_token={accessToken}&alt=json

A list of the types of queries you can send and their parameters are available here:

这篇关于如何获得Gmail联系人使用JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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