admin管理员组文章数量:1323225
Hello my main goal is to grab all the events from a google calendar and display their name with the date (and time if available) underneath. I am using the javascript google calendar api v3 and are running into troubles grabbing the date for each event. Before I explain my problems further here is the current code:
var clientId = '200816328603.apps.googleusercontent';
var apiKey = 'AIzaSyD3rbV__d8u6r9u5GioBU0oVwa-53YXRqM';
var scopes = '';
function handleClientLoad() {
gapi.client.setApiKey(apiKey);
window.setTimeout(checkAuth,1);
checkAuth();
}
function checkAuth() {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true},
handleAuthResult);
}
function handleAuthResult(authResult) {
var authorizeButton = document.getElementById('authorize-button');
if (authResult) {
authorizeButton.style.visibility = 'hidden';
makeApiCall();
} else {
authorizeButton.style.visibility = '';
authorizeButton.onclick = handleAuthClick;
}
}
function handleAuthClick(event) {
gapi.auth.authorize(
{client_id: clientId, scope: scopes, immediate: false},
handleAuthResult);
return false;
}
//document.createTextNode(resp.items[i].summary)
function makeApiCall() {
gapi.client.load('calendar', 'v3', function() {
var request = gapi.client.calendar.events.list({
'calendarId': 'pvhs.k12.nj.us_r6jaor04o80hpsaldf17civeio@group.calendar.google'
});
request.execute(function(resp) {
for (var i = 0; i < resp.items.length; i++) {
//---------nodes for html elements
var title = document.createTextNode(resp.items[i].summary); //titles are undefined so I'm using the summary as title instead
//var description = document.createTextNode(resp.items[i].description); //there are no descriptions apparently
var date = document.createTextNode('Start: ' + resp.items[i].start.date + ' End: ' + resp.items[i].end.date); //resp.items[i].date returns undefined
//---------html elements
var div = document.createElement('div');
div.className = resp.items[i].summary;
var h1 = document.createElement('h1');
h1.appendChild(title);
div.appendChild(h1);
//loop is to filter out all the undefined
if (date.textContent != 'Start: undefined End: undefined') {
var p = document.createElement('p');
p.appendChild(date);
div.appendChild(p);
}
document.body.appendChild(div);
}
});
});
}
Now resp.items[i].start.date and resp.items[i].end.date will return the date occasionally but sometimes just return undefined. How else can I grab the date of the event then?
My idea to get around this was to loop through every day of the month and grab all the events for that day. However when I tried adding the timeMax and timeMin parameters with the RFC3339 timestamp for the wanted day it didn't return anything. Could someone provide me with an example for acplishing this?
Any help is greatly appreciated.
Hello my main goal is to grab all the events from a google calendar and display their name with the date (and time if available) underneath. I am using the javascript google calendar api v3 and are running into troubles grabbing the date for each event. Before I explain my problems further here is the current code:
var clientId = '200816328603.apps.googleusercontent.';
var apiKey = 'AIzaSyD3rbV__d8u6r9u5GioBU0oVwa-53YXRqM';
var scopes = 'https://www.googleapis./auth/calendar';
function handleClientLoad() {
gapi.client.setApiKey(apiKey);
window.setTimeout(checkAuth,1);
checkAuth();
}
function checkAuth() {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true},
handleAuthResult);
}
function handleAuthResult(authResult) {
var authorizeButton = document.getElementById('authorize-button');
if (authResult) {
authorizeButton.style.visibility = 'hidden';
makeApiCall();
} else {
authorizeButton.style.visibility = '';
authorizeButton.onclick = handleAuthClick;
}
}
function handleAuthClick(event) {
gapi.auth.authorize(
{client_id: clientId, scope: scopes, immediate: false},
handleAuthResult);
return false;
}
//document.createTextNode(resp.items[i].summary)
function makeApiCall() {
gapi.client.load('calendar', 'v3', function() {
var request = gapi.client.calendar.events.list({
'calendarId': 'pvhs.k12.nj.us_r6jaor04o80hpsaldf17civeio@group.calendar.google.'
});
request.execute(function(resp) {
for (var i = 0; i < resp.items.length; i++) {
//---------nodes for html elements
var title = document.createTextNode(resp.items[i].summary); //titles are undefined so I'm using the summary as title instead
//var description = document.createTextNode(resp.items[i].description); //there are no descriptions apparently
var date = document.createTextNode('Start: ' + resp.items[i].start.date + ' End: ' + resp.items[i].end.date); //resp.items[i].date returns undefined
//---------html elements
var div = document.createElement('div');
div.className = resp.items[i].summary;
var h1 = document.createElement('h1');
h1.appendChild(title);
div.appendChild(h1);
//loop is to filter out all the undefined
if (date.textContent != 'Start: undefined End: undefined') {
var p = document.createElement('p');
p.appendChild(date);
div.appendChild(p);
}
document.body.appendChild(div);
}
});
});
}
Now resp.items[i].start.date and resp.items[i].end.date will return the date occasionally but sometimes just return undefined. How else can I grab the date of the event then?
My idea to get around this was to loop through every day of the month and grab all the events for that day. However when I tried adding the timeMax and timeMin parameters with the RFC3339 timestamp for the wanted day it didn't return anything. Could someone provide me with an example for acplishing this?
Any help is greatly appreciated.
Share Improve this question asked Apr 9, 2013 at 23:50 ConnorConnor 511 silver badge3 bronze badges1 Answer
Reset to default 8In order to use timeMin or timeMax you need to set 'singleEvents' to true which I believe returns individual instances of reoccurring events instead of the event group.
var request = gapi.client.calendar.events.list({
'calendarId': 'pvhs.k12.nj.us_r6jaor04o80hpsaldf17civeio@group.calendar.google.',
'singleEvents': true, /* required to use timeMin */
'timeMin': '2013-02-01T11:43:22.000Z'
});
hope that helps.
本文标签: Get events from a certain day with the javascript google calendar api v3Stack Overflow
版权声明:本文标题:Get events from a certain day with the javascript google calendar api v3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742070403a2419088.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论