-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.html
96 lines (84 loc) · 3.64 KB
/
index2.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
<html>
<head>
<title>v4</title>
</head>
<body>
<!--
BEFORE RUNNING:
---------------
1. If not already done, enable the Google Sheets API
and check the quota for your project at
https://console.developers.google.com/apis/api/sheets
2. Get access keys for your application. See
https://developers.google.com/api-client-library/javascript/start/start-js#get-access-keys-for-your-application
3. For additional information on authentication, see
https://developers.google.com/sheets/api/quickstart/js#step_2_set_up_the_sample
-->
<script>
function makeApiCall() {
var params = {
// The ID of the spreadsheet to retrieve data from.
spreadsheetId: '1JSpPrWfo-CWW0q5GwbWUah-bvuQA2hRPNL1Ht53hIkY', // TODO: Update placeholder value.
// The A1 notation of the values to retrieve.
range: 'R1C1', // TODO: Update placeholder value.
// How values should be represented in the output.
// The default render option is ValueRenderOption.FORMATTED_VALUE.
// valueRenderOption: '', // TODO: Update placeholder value.
// How dates, times, and durations should be represented in the output.
// This is ignored if value_render_option is
// FORMATTED_VALUE.
// The default dateTime render option is [DateTimeRenderOption.SERIAL_NUMBER].
// dateTimeRenderOption: '', // TODO: Update placeholder value.
};
var request = gapi.client.sheets.spreadsheets.values.get(params);
request.then(function(response) {
console.log(response);
// TODO: Change code below to process the `response` object:
console.log(response.result);
}, function(reason) {
console.error('error: ' + reason.result.error.message);
});
}
function initClient() {
var API_KEY = 'AIzaSyBRW6aMCSm4aoo636LnVIExSMYWuow7IV4'; // TODO: Update placeholder with desired API key.
var CLIENT_ID = '911151820985-ble4mlioiaqb5grec4o0arcc8qc74g5s.apps.googleusercontent.com'; // TODO: Update placeholder with desired client ID.
// TODO: Authorize using one of the following scopes:
// 'https://www.googleapis.com/auth/drive'
// 'https://www.googleapis.com/auth/drive.file'
// 'https://www.googleapis.com/auth/drive.readonly'
// 'https://www.googleapis.com/auth/spreadsheets'
// 'https://www.googleapis.com/auth/spreadsheets.readonly'
var SCOPE = 'https://www.googleapis.com/auth/spreadsheets.readonly';
gapi.client.init({
'apiKey': API_KEY,
'clientId': CLIENT_ID,
'scope': SCOPE,
'discoveryDocs': ['https://sheets.googleapis.com/$discovery/rest?version=v4'],
}).then(function() {
gapi.auth2.getAuthInstance().isSignedIn.listen(updateSignInStatus);
updateSignInStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
});
}
function handleClientLoad() {
gapi.load('client:auth2', initClient);
}
function updateSignInStatus(isSignedIn) {
if (isSignedIn) {
makeApiCall();
}
}
function handleSignInClick(event) {
gapi.auth2.getAuthInstance().signIn();
}
function handleSignOutClick(event) {
gapi.auth2.getAuthInstance().signOut();
}
</script>
<script async defer src="https://apis.google.com/js/api.js"
onload="this.onload=function(){};handleClientLoad()"
onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>
<button id="signin-button" onclick="handleSignInClick()">Sign in</button>
<button id="signout-button" onclick="handleSignOutClick()">Sign out</button>
</body>
</html>