forked from wora/google-api-javascript-client
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathissue6.html
More file actions
120 lines (105 loc) · 3.54 KB
/
issue6.html
File metadata and controls
120 lines (105 loc) · 3.54 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>External issue #6</title>
<script>
// External JSC Test
var API_KEY = 'AIzaSyAjUuIYvtq2uNudxnnDlFvaQBcfw-fWuRQ';
var CLIENT_ID = '142810797254-hrlfpalkm629scejnjkqdmrgn7u2opqh';
var SCOPES = 'https://www.googleapis.com/auth/tasks';
function authInit() {
gapi.client.setApiKey(API_KEY);
window.setTimeout(checkAuth,1);
}
function checkAuth() {
gapi.auth.authorize({
client_id: CLIENT_ID,
scope: SCOPES,
immediate: true
}, handleAuthResult);
}
function handleAuthResult(authResult) {
var authorizeButton = document.getElementById('authorize-button');
var tasksView = document.getElementById('tasksView');
if (authResult) {
authorizeButton.style.display = 'none';
tasksView.style.display = '';
} else {
tasksView.style.display = 'none';
authorizeButton.style.display = '';
authorizeButton.onclick = handleAuthClick;
}
}
function handleAuthClick(event) {
gapi.auth.authorize({
client_id: CLIENT_ID,
scope: SCOPES,
immediate: false
}, handleAuthResult);
return false;
}
function addLogItem(text) {
var log = document.getElementById('log');
var logItem = document.createElement('p');
logItem.appendChild(document.createTextNode(text));
log.appendChild(logItem);
};
var tasklistId;
var taskId;
function listTasklists() {
gapi.client.request({
'path': '/tasks/v1/users/@me/lists',
'callback': handleListTasklists
});
}
function handleListTasklists(response) {
var tasklists = response && response.items;
if (!tasklists || !tasklists.length) { throw('no tasklists'); }
tasklistId = tasklists[0].id;
addLogItem('Using tasklist ID: ' + tasklistId);
createTask();
}
function createTask() {
gapi.client.request({
'path': '/tasks/v1/lists/' + tasklistId + '/tasks',
'method': 'POST',
'body': JSON.stringify({
'title': 'Test Task'
}),
'callback': handleCreateTask
});
};
function handleCreateTask(response) {
if (!response || !response.id) { throw('Failed to create task'); }
addLogItem('Created task.')
addLogItem('Title: ' + response.title + ', ID: ' + response.id);
taskId = response.id
deleteTask();
}
function deleteTask() {
if (!taskId) { throw('no task to delete'); }
gapi.client.request({
'path': '/tasks/v1/lists/' + tasklistId + '/tasks/' + taskId,
'method': 'DELETE',
'callback': handleDeleteTask
});
}
function handleDeleteTask(response) {
if (!response) {
// No news is good news.
addLogItem('Task ' + taskId + ' successfully deleted.');
}
}
</script>
<script src="https://apis.google.com/js/client.js?onload=authInit"></script>
</head>
<body>
<button id="authorize-button" style="display:none;">Authorize</button>
<div id="tasksView" style="display:none;">
<button id="deleteTask" onclick="listTasklists();">Delete Task</button>
<span id="log">
</span>
</div>
</body>
</html>