Skip to content

Instantly share code, notes, and snippets.

@luanrm
Last active April 11, 2016 19:34
Show Gist options
  • Save luanrm/3a0b5744e6fc8b6d5dc1ee53cf4849df to your computer and use it in GitHub Desktop.
Save luanrm/3a0b5744e6fc8b6d5dc1ee53cf4849df to your computer and use it in GitHub Desktop.
var CLIENT_ID = web.client_id;
var SCOPES = ["https://www.googleapis.com/auth/calendar"];
function checkAuth() {
gapi.auth.authorize(
{
'client_id': CLIENT_ID,
'scope': SCOPES.join(' '),
'immediate': true
}, handleAuthResult);
}
function handleAuthResult(authResult) {
var authorizeDiv = document.getElementById('authorize-div');
if (authResult && !authResult.error) {
authorizeDiv.style.display = 'none';
loadCalendarApi();
} else {
authorizeDiv.style.display = 'inline';
}
}
function handleAuthClick(event) {
gapi.auth.authorize(
{client_id: CLIENT_ID, scope: SCOPES, immediate: false},
handleAuthResult);
return false;
}
function loadCalendarApi() {
gapi.client.load('calendar', 'v3', listUpcomingEvents);
}
function listUpcomingEvents() {
var event = {
'summary': 'ocupado',
'start': {
'dateTime': '2016-04-16T09:00:00-07:00',
'timeZone': 'America/Los_Angeles'
},
'end': {
'dateTime': '2016-04-16T17:00:00-07:00',
'timeZone': 'America/Los_Angeles'
}
};
var request = gapi.client.calendar.events.update({
'calendarId': 'primary',
'eventId' : '91omdjkqse514b05uubben1npc',
'resource': event
});
request.execute(function(event) {
appendPre('Event created: ' + event.htmlLink);
});
}
function appendPre(message) {
var pre = document.getElementById('output');
var textContent = document.createTextNode(message + '\n');
pre.appendChild(textContent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment