Table of Contents
Step 1.  Send an Authentication Request to Google
Step 3. Get Events List NOW!
Home Database Mysql Tutorial 【Google Calendar API v3】get events list with OAuth 2.0 &

【Google Calendar API v3】get events list with OAuth 2.0 &

Jun 07, 2016 pm 03:43 PM
api calendar events get google

It took me some time to learn about the Google Calendar API V3 and I have encountered some problems. So it is necessary to summary the steps, just take the 'event list' as an example. The event list API is here:https://developers.google.co

It took me some time to learn about the Google Calendar API V3 and I have encountered some problems. So it is necessary to summary the steps, just take the 'event list' as an example.


The event list API is here: https://developers.google.com/google-apps/calendar/v3/reference/events/list


Details of using OAuth 2.0 for Login is here: https://developers.google.com/accounts/docs/OAuth2Login


Assumption: you have alreay registered your app and turn the Calendar API 'ON' in the 'API & auth' sidebar.


Note: The request needs authorization and I use OAuth 2.0, here are the steps.


Step 1.  Send an Authentication Request to Google

HTTP GET: https://accounts.google.com/o/oauth2/auth?

client_id=XXXXXXXXX&

response_type=code&

scope=https://www.googleapis.com/auth/calendar&

redirect_uri=XXXXXXXXX&

login_hint=XXXXXX


client_id: can be seen in your Google Cloud Console.

redirect_uri: also in your Google Cloud Console, you must write it down in your registered apps page.

login_hint=google account


Then your will find the code parameter in the redirect uri.


Step 2. Exchange Code for Access Token and ID Token

Use the code you got in the last step to post request. The actual request might look like:

<span>POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded

code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7&amp;
client_id=8819981768.apps.googleusercontent.com&amp;
client_secret={client_secret}&amp;
redirect_uri=https://oauth2-login-demo.appspot.com/code&amp;
grant_type=authorization_code</span>
Copy after login

I use the Chrome Plugin Rest Client to post the request and get access token.

【Google Calendar API v3】get events list with OAuth 2.0 &

Then you will get the access_token in the response.


Step 3. Get Events List NOW!

With the access_token, you are able to request the event list according to Google Calendar API.
The whole HTTP GET URI is like:


https://www.googleapis.com/calendar/v3/calendars/{your calendar id}/events?

code=XXXXXX&

client_id=XXXXXX&

client_secret=XXXXXX&

redirect_uri=XXXXX&

grant_type=authorization_code

&access_token=XXXXXXXX


{your calendar id} is your google account, looks like XXX@gmail.com


Then you will get the JSON response!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Google Pixel 9 and Pixel 9 Pro rumoured to gain Creative Assistant AI upon release Google Pixel 9 and Pixel 9 Pro rumoured to gain Creative Assistant AI upon release Jun 22, 2024 am 10:50 AM

Google Pixel 9 and Pixel 9 Pro rumoured to gain Creative Assistant AI upon release

Google Tensor G4 of Pixel 9 Pro XL lags behind Tensor G2 in Genshin Impact Google Tensor G4 of Pixel 9 Pro XL lags behind Tensor G2 in Genshin Impact Aug 24, 2024 am 06:43 AM

Google Tensor G4 of Pixel 9 Pro XL lags behind Tensor G2 in Genshin Impact

Google app beta APK teardown reveals new extensions coming to Gemini AI assistant Google app beta APK teardown reveals new extensions coming to Gemini AI assistant Jul 30, 2024 pm 01:06 PM

Google app beta APK teardown reveals new extensions coming to Gemini AI assistant

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers Google AI announces Gemini 1.5 Pro and Gemma 2 for developers Jul 01, 2024 am 07:22 AM

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers

Google Pixel 9 smartphones will not launch with Android 15 despite seven-year update commitment Google Pixel 9 smartphones will not launch with Android 15 despite seven-year update commitment Aug 01, 2024 pm 02:56 PM

Google Pixel 9 smartphones will not launch with Android 15 despite seven-year update commitment

New Google Pixel desktop mode showcased in fresh video as possible Motorola Ready For and Samsung DeX alternative New Google Pixel desktop mode showcased in fresh video as possible Motorola Ready For and Samsung DeX alternative Aug 08, 2024 pm 03:05 PM

New Google Pixel desktop mode showcased in fresh video as possible Motorola Ready For and Samsung DeX alternative

Google Pixel 9 Pro XL gets tested with desktop mode Google Pixel 9 Pro XL gets tested with desktop mode Aug 29, 2024 pm 01:09 PM

Google Pixel 9 Pro XL gets tested with desktop mode

Google opens AI Test Kitchen & Imagen 3 to most users Google opens AI Test Kitchen & Imagen 3 to most users Sep 12, 2024 pm 12:17 PM

Google opens AI Test Kitchen & Imagen 3 to most users

See all articles