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.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- Carriage Return (ASCII chr 13) is missing from tex
- void before promise syntax
- Keeping track of variable instances
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 aGET
address to the following URI:A list of the types of queries you can send and their parameters are available here:
To get users' contacts using OAuth, first you need to specify the contact's scope in your request. If you're using ChromeExAuth, then you would write:
The scope parameter above lists 3 scopes: the user's email, profile, and contacts (
google.com/m8/feeds/contacts
)To get their contacts after the user authorizes the token, you would send a request like this:
And the callback for the request could look like this:
To view the contacts array, you could just print on the console:
You can checkout the Google OAuth tutorial here