· 6 years ago · Mar 04, 2020, 02:34 PM
1--- Guide ---
2https://developers.google.com/identity/protocols/OAuth2ForDevices
3
4--- Steps ---
51 - Go to URL
6 https://console.developers.google.com
7
82 - Navigate
9 (Top Left) Select A Project -> New Project
10 Library -> Google Calendar API -> Enable
11
12 (Left) Credentials -> Configure Consent Screen
13 Internal
14 Application Name
15 Add Scopes -> calendar.readonly, calendar.events.readonly
16
17 (Left) Credentials -> Create Credentials -> OAuth Client ID
18 Other -> Name
19 Copy Client ID, Client Secret
20
213 - Follow Guide
22 https://developers.google.com/identity/protocols/OAuth2ForDevices#obtaining-oauth-2.0-access-tokens
23
24
25*** Guide Details ***
26
27------ Request API Key ------
28POST /device/code HTTP/1.1
29Host: oauth2.googleapis.com
30Content-Type: application/x-www-form-urlencoded
31
32client_id=[client_id]&scope=calendar.readonly%20calendar.events.readonly
33------ Response ------
34{
35 "device_code": "4/4-GMMhmHCXhWEzkobqIHGG_EnNYYsAkukHspeYUk9E8",
36 "user_code": "GQVQ-JKEC",
37 "verification_url": "https://www.google.com/device",
38 "expires_in": 1800,
39 "interval": 5
40}
41------ ------
421. Show verification_url
432. Show user_code
443. Grant access via browser
45
46------ Poll Every [interval] seconds ------
47POST /token HTTP/1.1
48Host: oauth2.googleapis.com
49Content-Type: application/x-www-form-urlencoded
50
51client_id=[client_id]&
52client_secret=[client_secret]&
53code=[device_code]&
54grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code
55------ Response Access Granted ------
56{
57 "access_token": "1/fFAGRNJru1FTz70BzhT3Zg",
58 "expires_in": 3920,
59 "scope": "openid https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
60 "token_type": "Bearer",
61 "refresh_token": "1/xEoDL4iW3cxlI7yDbSRFYNG01kVKM2C-259HOF2aQbI"
62}
63------ ------
64Wait for Access Granted (200 OK ???)
65Errors (400, 401)
66
67API Reference:
68https://developers.google.com/calendar/v3/reference/?apix=true#Events
69
70------ Get Events ------
71GET /calendar/v3/calendars/[calendarId]/events[API] HTTP/1.1
72Host: www.googleapis.com
73Authorization: Bearer [access_token]
74------ Response ------
75{
76 "kind": "calendar#events",
77 "etag": etag,
78 "summary": string,
79 "description": string,
80 "updated": datetime,
81 "timeZone": string,
82 "accessRole": string,
83 "defaultReminders": [
84 {
85 "method": string,
86 "minutes": integer
87 }
88 ],
89 "nextPageToken": string,
90 "nextSyncToken": string,
91 "items": [
92 events Resource
93 ]
94}
95------ ------
96
97Event structure - https://developers.google.com/calendar/v3/reference/events#resource
98 - start.dateTime
99 - end.dateTime
100
101------ Token Refresh ------
102POST /token HTTP/1.1
103Host: oauth2.googleapis.com
104Content-Type: application/x-www-form-urlencoded
105
106client_id=[client_id]&
107client_secret=[client_secret]&
108refresh_token=[refresh_token]&
109grant_type=refresh_token
110------ Response ------
111{
112 "access_token": "1/fFAGRNJru1FTz70BzhT3Zg",
113 "expires_in": 3920,
114 "scope": "https://www.googleapis.com/auth/drive.metadata.readonly",
115 "token_type": "Bearer"
116}
117------ ------