|
1 |
| -/* Example taken from Google Calendar API JavaScript Quickstart https://developers.google.com/google-apps/calendar/quickstart/js */ |
2 |
| - |
3 |
| -{ |
4 |
| - // Your Client ID can be retrieved from your project in the Google |
5 |
| - // Developer Console, https://console.developers.google.com |
6 |
| - var CLIENT_ID = '<YOUR_CLIENT_ID>'; |
7 |
| - |
8 |
| - var SCOPES = ["https://www.googleapis.com/auth/calendar.readonly"]; |
9 |
| - |
10 |
| - /** |
11 |
| - * Check if current user has authorized this application. |
12 |
| - */ |
13 |
| - function checkAuth() { |
14 |
| - gapi.auth.authorize( |
15 |
| - { |
16 |
| - 'client_id': CLIENT_ID, |
17 |
| - 'scope': SCOPES.join(' '), |
18 |
| - 'immediate': true |
19 |
| - }, handleAuthResult); |
20 |
| - } |
21 |
| - |
22 |
| - /** |
23 |
| - * Handle response from authorization server. |
24 |
| - * |
25 |
| - * @param {Object} authResult Authorization result. |
26 |
| - */ |
27 |
| - function handleAuthResult(authResult: GoogleApiOAuth2TokenObject) { |
28 |
| - var authorizeDiv = document.getElementById('authorize-div')!; |
29 |
| - if (authResult && !authResult.error) { |
30 |
| - // Hide auth UI, then load client library. |
31 |
| - authorizeDiv.style.display = 'none'; |
32 |
| - loadCalendarApi(); |
33 |
| - } else { |
34 |
| - // Show auth UI, allowing the user to initiate authorization by |
35 |
| - // clicking authorize button. |
36 |
| - authorizeDiv.style.display = 'inline'; |
37 |
| - } |
38 |
| - } |
39 |
| - |
40 |
| - /** |
41 |
| - * Initiate auth flow in response to user clicking authorize button. |
42 |
| - * |
43 |
| - * @param {Event} event Button click event. |
44 |
| - */ |
45 |
| - function handleAuthClick(event: MouseEvent) { |
46 |
| - gapi.auth.authorize( |
47 |
| - {client_id: CLIENT_ID, scope: SCOPES, immediate: false}, |
48 |
| - handleAuthResult); |
49 |
| - return false; |
50 |
| - } |
51 |
| - |
52 |
| - /** |
53 |
| - * Load Google Calendar client library. List upcoming events |
54 |
| - * once client library is loaded. |
55 |
| - */ |
56 |
| - function loadCalendarApi() { |
57 |
| - gapi.client.load('calendar', 'v3', listUpcomingEvents); |
58 |
| - } |
59 |
| - |
60 |
| - /** |
61 |
| - * Print the summary and start datetime/date of the next ten events in |
62 |
| - * the authorized user's calendar. If no events are found an |
63 |
| - * appropriate message is printed. |
64 |
| - */ |
65 |
| - function listUpcomingEvents() { |
66 |
| - var request = gapi.client.calendar.events.list({ |
67 |
| - 'calendarId': 'primary', |
68 |
| - 'timeMin': (new Date()).toISOString(), |
69 |
| - 'showDeleted': false, |
70 |
| - 'singleEvents': true, |
71 |
| - 'maxResults': 10, |
72 |
| - 'orderBy': 'startTime' |
73 |
| - }); |
74 |
| - |
75 |
| - request.execute(function(resp) { |
76 |
| - var events = resp.items; |
77 |
| - appendPre('Upcoming events:'); |
78 |
| - |
79 |
| - if (events.length > 0) { |
80 |
| - for (let i = 0; i < events.length; i++) { |
81 |
| - var event = events[i]; |
82 |
| - var when = event.start.dateTime; |
83 |
| - if (!when) { |
84 |
| - when = event.start.date; |
85 |
| - } |
86 |
| - appendPre(event.summary + ' (' + when + ')') |
87 |
| - } |
88 |
| - } else { |
89 |
| - appendPre('No upcoming events found.'); |
90 |
| - } |
91 |
| - |
92 |
| - }); |
93 |
| - } |
94 |
| - |
95 |
| - /** |
96 |
| - * Append a pre element to the body containing the given message |
97 |
| - * as its text node. |
98 |
| - * |
99 |
| - * @param {string} message Text to be placed in pre element. |
100 |
| - */ |
101 |
| - function appendPre(message: string) { |
102 |
| - var pre = document.getElementById('output')!; |
103 |
| - var textContent = document.createTextNode(message + '\n'); |
104 |
| - pre.appendChild(textContent); |
105 |
| - } |
106 |
| -} |
107 |
| - |
108 |
| -/* Example taken from https://developers.google.com/google-apps/calendar/v3/reference/events/insert#examples */ |
109 |
| - |
110 |
| -{ |
111 |
| - // Refer to the JavaScript quickstart on how to setup the environment: |
112 |
| - // https://developers.google.com/google-apps/calendar/quickstart/js |
113 |
| - // Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any |
114 |
| - // stored credentials. |
115 |
| - |
116 |
| - const event = { |
117 |
| - 'summary': 'Google I/O 2015', |
118 |
| - 'location': '800 Howard St., San Francisco, CA 94103', |
119 |
| - 'description': 'A chance to hear more about Google\'s developer products.', |
120 |
| - 'start': { |
121 |
| - 'dateTime': '2015-05-28T09:00:00-07:00', |
122 |
| - 'timeZone': 'America/Los_Angeles' |
123 |
| - }, |
124 |
| - 'end': { |
125 |
| - 'dateTime': '2015-05-28T17:00:00-07:00', |
126 |
| - 'timeZone': 'America/Los_Angeles' |
127 |
| - }, |
128 |
| - 'recurrence': [ |
129 |
| - 'RRULE:FREQ=DAILY;COUNT=2' |
130 |
| - ], |
131 |
| - 'attendees': [ |
132 |
| - |
133 |
| - |
134 |
| - ], |
135 |
| - 'reminders': { |
136 |
| - 'useDefault': false, |
137 |
| - 'overrides': [ |
138 |
| - {'method': 'email', 'minutes': 24 * 60}, |
139 |
| - {'method': 'popup', 'minutes': 10} |
140 |
| - ] |
141 |
| - } |
142 |
| - }; |
143 |
| - |
144 |
| - var request = gapi.client.calendar.events.insert({ |
145 |
| - 'calendarId': 'primary', |
146 |
| - 'resource': event |
147 |
| - }); |
148 |
| - |
149 |
| - request.execute(function(event) { |
150 |
| - appendPre('Event created: ' + event.htmlLink); |
151 |
| - }); |
152 |
| -} |
| 1 | +/* Example taken from Google Calendar API JavaScript Quickstart https://developers.google.com/google-apps/calendar/quickstart/js */ |
| 2 | + |
| 3 | +{ |
| 4 | + // Your Client ID can be retrieved from your project in the Google |
| 5 | + // Developer Console, https://console.developers.google.com |
| 6 | + var CLIENT_ID = '<YOUR_CLIENT_ID>'; |
| 7 | + |
| 8 | + var SCOPES = ["https://www.googleapis.com/auth/calendar.readonly"]; |
| 9 | + |
| 10 | + /** |
| 11 | + * Check if current user has authorized this application. |
| 12 | + */ |
| 13 | + function checkAuth() { |
| 14 | + gapi.auth.authorize( |
| 15 | + { |
| 16 | + 'client_id': CLIENT_ID, |
| 17 | + 'scope': SCOPES.join(' '), |
| 18 | + 'immediate': true |
| 19 | + }, handleAuthResult); |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * Handle response from authorization server. |
| 24 | + * |
| 25 | + * @param {Object} authResult Authorization result. |
| 26 | + */ |
| 27 | + function handleAuthResult(authResult: GoogleApiOAuth2TokenObject) { |
| 28 | + var authorizeDiv = document.getElementById('authorize-div')!; |
| 29 | + if (authResult && !authResult.error) { |
| 30 | + // Hide auth UI, then load client library. |
| 31 | + authorizeDiv.style.display = 'none'; |
| 32 | + loadCalendarApi(); |
| 33 | + } else { |
| 34 | + // Show auth UI, allowing the user to initiate authorization by |
| 35 | + // clicking authorize button. |
| 36 | + authorizeDiv.style.display = 'inline'; |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Initiate auth flow in response to user clicking authorize button. |
| 42 | + * |
| 43 | + * @param {Event} event Button click event. |
| 44 | + */ |
| 45 | + function handleAuthClick(event: MouseEvent) { |
| 46 | + gapi.auth.authorize( |
| 47 | + {client_id: CLIENT_ID, scope: SCOPES, immediate: false}, |
| 48 | + handleAuthResult); |
| 49 | + return false; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Load Google Calendar client library. List upcoming events |
| 54 | + * once client library is loaded. |
| 55 | + */ |
| 56 | + function loadCalendarApi() { |
| 57 | + gapi.client.load('calendar', 'v3', listUpcomingEvents); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Print the summary and start datetime/date of the next ten events in |
| 62 | + * the authorized user's calendar. If no events are found an |
| 63 | + * appropriate message is printed. |
| 64 | + */ |
| 65 | + function listUpcomingEvents() { |
| 66 | + var request = gapi.client.calendar.events.list({ |
| 67 | + 'calendarId': 'primary', |
| 68 | + 'timeMin': (new Date()).toISOString(), |
| 69 | + 'showDeleted': false, |
| 70 | + 'singleEvents': true, |
| 71 | + 'maxResults': 10, |
| 72 | + 'orderBy': 'startTime' |
| 73 | + }); |
| 74 | + |
| 75 | + request.execute(function(resp) { |
| 76 | + var events = resp.items; |
| 77 | + appendPre('Upcoming events:'); |
| 78 | + |
| 79 | + if (events.length > 0) { |
| 80 | + for (let i = 0; i < events.length; i++) { |
| 81 | + var event = events[i]; |
| 82 | + var when = event.start.dateTime; |
| 83 | + if (!when) { |
| 84 | + when = event.start.date; |
| 85 | + } |
| 86 | + appendPre(event.summary + ' (' + when + ')') |
| 87 | + } |
| 88 | + } else { |
| 89 | + appendPre('No upcoming events found.'); |
| 90 | + } |
| 91 | + |
| 92 | + }); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Append a pre element to the body containing the given message |
| 97 | + * as its text node. |
| 98 | + * |
| 99 | + * @param {string} message Text to be placed in pre element. |
| 100 | + */ |
| 101 | + function appendPre(message: string) { |
| 102 | + var pre = document.getElementById('output')!; |
| 103 | + var textContent = document.createTextNode(message + '\n'); |
| 104 | + pre.appendChild(textContent); |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +/* Example taken from https://developers.google.com/google-apps/calendar/v3/reference/events/insert#examples */ |
| 109 | + |
| 110 | +{ |
| 111 | + // Refer to the JavaScript quickstart on how to setup the environment: |
| 112 | + // https://developers.google.com/google-apps/calendar/quickstart/js |
| 113 | + // Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any |
| 114 | + // stored credentials. |
| 115 | + |
| 116 | + const event = { |
| 117 | + 'summary': 'Google I/O 2015', |
| 118 | + 'location': '800 Howard St., San Francisco, CA 94103', |
| 119 | + 'description': 'A chance to hear more about Google\'s developer products.', |
| 120 | + 'start': { |
| 121 | + 'dateTime': '2015-05-28T09:00:00-07:00', |
| 122 | + 'timeZone': 'America/Los_Angeles' |
| 123 | + }, |
| 124 | + 'end': { |
| 125 | + 'dateTime': '2015-05-28T17:00:00-07:00', |
| 126 | + 'timeZone': 'America/Los_Angeles' |
| 127 | + }, |
| 128 | + 'recurrence': [ |
| 129 | + 'RRULE:FREQ=DAILY;COUNT=2' |
| 130 | + ], |
| 131 | + 'attendees': [ |
| 132 | + |
| 133 | + |
| 134 | + ], |
| 135 | + 'reminders': { |
| 136 | + 'useDefault': false, |
| 137 | + 'overrides': [ |
| 138 | + {'method': 'email', 'minutes': 24 * 60}, |
| 139 | + {'method': 'popup', 'minutes': 10} |
| 140 | + ] |
| 141 | + } |
| 142 | + }; |
| 143 | + |
| 144 | + var request = gapi.client.calendar.events.insert({ |
| 145 | + 'calendarId': 'primary', |
| 146 | + 'resource': event |
| 147 | + }); |
| 148 | + |
| 149 | + request.execute(function(event) { |
| 150 | + appendPre('Event created: ' + event.htmlLink); |
| 151 | + }); |
| 152 | +} |
0 commit comments