-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.html
37 lines (36 loc) · 1.71 KB
/
demo.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
<script src="https://apis.google.com/js/api.js"></script>
<script>
/**
* Sample JavaScript code for calendar.calendarList.list
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/code-samples#javascript
*/
function authenticate() {
return gapi.auth2.getAuthInstance()
.signIn({scope: "https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/calendar.readonly", plugin_name: 'dinnerwithfriends'})
.then(function() { console.log("Sign-in successful"); },
function(err) { console.error("Error signing in", err); });
}
function loadClient() {
gapi.client.setApiKey("AIzaSyA7G2ANAJI6rm_DpTW84lsKUJT-c8bmirI");
return gapi.client.load("https://content.googleapis.com/discovery/v1/apis/calendar/v3/rest")
.then(function() { console.log("GAPI client loaded for API");
execute()
},
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
return gapi.client.calendar.calendarList.list({})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: "102076896830-4il8ncmrd6qfoippk2ut4uujb8cci54v.apps.googleusercontent.com"});
});
</script>
<button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="execute()">execute</button>