-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoogleCalendarTest.html
246 lines (223 loc) · 6.91 KB
/
GoogleCalendarTest.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-align: center;
}
div {
border-radius: 5px;
background-color: #b0e0e6;
padding: 20px;
}
input[type=text] {
width: 20%;
padding: 8px 14px;
margin: 8px 0;
display: inline-block;
border: 1px solid #008080;
border-radius: 4px;
box-sizing: border-box;
background-color: #00ffff;
}
input[type=email] {
width: 20%;
padding: 8px 14px;
margin: 8px 0;
display: inline-block;
border: 1px solid #008080;
border-radius: 4px;
box-sizing: border-box;
background-color: #00ffff;
}
input[type=dateTime] {
width: 20%;
padding: 8px 14px;
margin: 8px 0;
display: inline-block;
border: 1px solid #008080;
border-radius: 4px;
box-sizing: border-box;
background-color: #00ffff
}
input[type=button]{
background-color: #4CAF50;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
}
button {
background-color: #008CBA;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
-webkit-transition-duration: 0.4s;
transition-duration: 0.4s;
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}
</style>
<title>Google Calendar API Quickstart</title>
<meta charset='utf-8' />
</head>
<body>
<h1 style="color:blue;margin-center:30px;"> Google Calendar</h1>
<div>
Summary:
<input type="text" id="summary1" maxlength="50" placeholder="What is it..">
Location:
<input type="text" id="location1" maxlength="50" placeholder="Where is it..">
Description
<input type="text" id="description1" maxlength="70" placeholder="Write something about it..">
<p><font color="##0000FF">Date and Time must be in this form ( 2017-10-26T10:00:00 ) </font></p>
Start Time:
<input type="datetime" id="startTime1" maxlength="19" placeholder="0000-00-00T00:00:00">
End Time:
<input type="datetime" id="endTime1" maxlength="19" placeholder="0000-00-00T00:00:00">
Attendees:
<input type="email" id="email1" maxlength="50" placeholder="Write an E-mail..">
</div>
<button onclick="insertEvent()">Create Event</button>
<button onclick="listUpcomingEvents()">show Event</button>
<script type="text/javascript">
// Your Client ID can be retrieved from your project in the Google
// Developer Console, https://console.developers.google.com
var CLIENT_ID = '843749328717-5rj5c0iuvaddlricoshtghnoq1290d1k.apps.googleusercontent.com';
var SCOPES = ["https://www.googleapis.com/auth/calendar"];
/**
* Check if current user has authorized this application.
*/
function checkAuth() {
gapi.auth.authorize(
{
'client_id': CLIENT_ID,
'scope': SCOPES.join(' '),
'immediate': true
}, handleAuthResult);
}
/**
* Handle response from authorization server.
*
* @param {Object} authResult Authorization result.
*/
function handleAuthResult(authResult) {
var authorizeDiv = document.getElementById('authorize-div');
if (authResult && !authResult.error) {
// Hide auth UI, then load client library.
authorizeDiv.style.display = 'none';
loadCalendarApi();
} else {
// Show auth UI, allowing the user to initiate authorization by
// clicking authorize button.
authorizeDiv.style.display = 'inline';
}
}
/**
* Initiate auth flow in response to user clicking authorize button.
*
* @param {Event} event Button click event.
*/
function handleAuthClick(event) {
gapi.auth.authorize(
{client_id: CLIENT_ID, scope: SCOPES, immediate: false},
handleAuthResult);
return false;
}
/**
* Load Google Calendar client library. List upcoming events
* once client library is loaded.
*/
function loadCalendarApi() {
gapi.client.load('calendar', 'v3', insertEvent);
}
/**
* Append a pre element to the body containing the given message
* as its text node.
*
* @param {string} message Text to be placed in pre element.
*/
function appendPre(message) {
var pre = document.getElementById('output');
var textContent = document.createTextNode(message + '\n');
pre.appendChild(textContent);
}
function insertEvent() {
var event = {
'summary' : document.getElementById('summary1').value,
'location': document.getElementById('location1').value,
'description': document.getElementById('description1').value,
'start': {
'dateTime': document.getElementById('startTime1').value,
'timeZone': 'GMT+02:00',
},
'end': {
'dateTime': document.getElementById('startTime1').value,
'timeZone': 'GMT+02:00',
},
'attendees': [
{'email': document.getElementById('email1').value,},
],
'reminders': {
'useDefault': false,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10}
]
}
};
var request = gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': event
});
request.execute(function(event) {
appendPre('Event created: ' + event.htmlLink);
console.log("Event added to Calendar");
});
}
function listUpcomingEvents() {
gapi.client.calendar.events.list({
'calendarId': 'primary',
'timeMin': (new Date()).toISOString(),
'showDeleted': false,
'singleEvents': true,
'maxResults': 10,
'orderBy': 'startTime'
}).then(function(response) {
var events = response.result.items;
appendPre('Upcoming events:');
if (events.length > 0) {
for (i = 0; i < events.length; i++) {
var event = events[i];
var when = event.start.dateTime;
if (!when) {
when = event.start.date;
}
appendPre(event.summary + ' (' + when + ')')
}
} else {
appendPre('No upcoming events found.');
}
});
}
</script>
<script src="https://apis.google.com/js/client.js?onload=checkAuth">
</script>
</head>
<body>
<div id="authorize-div" style="display: none">
<span>Authorize access to Google Calendar API</span>
<!--Button for the user to click to initiate auth sequence -->
<button id="authorize-button" onclick="handleAuthClick(event)">
Authorize
</button>
</div>
<pre id="output"></pre>
</body>
</html>