javascript - Retrieval of events Google calendar -
i resurrecting previous thread located here google api events list
i must missing because screen loading , updating. there goes in between ?
<!doctype html> <head> <title>event calendar | los angeles rams</title> </head> <body bgcolor="black" text="white" link="#00ffff" vlink="green" alink="yellow"> <script> var clientid = 'xxxxxxx-yyyyyyy.apps.googleusercontent.com'; //choose web app client id, redirect uri , javascript origin set http://localhost var apikey = 'xkb7btfakec4lwz6udmx3az'; //choose public apikey, ip allowed (leave blank allowed ip boxes in google dev console) var useremail = 'xxxxxxx@group.calendar.google.com'; //your calendar id var usertimezone = "los_angeles"; //example "rome" "los_angeles" ecc... var maxrows = 10; //events shown var calname = "hutty"; //name of calendar (write want, doesn't matter) var scopes = 'https://www.googleapis.com/auth/calendar'; //--------------------- add 0 numbers function padnum(num) { if (num <= 9) { return "0" + num; } return num; } //--------------------- end //--------------------- 24h am/pm function ampm(num) { if (num <= 12) { return "am " + num; } return "pm " + padnum(num - 12); } //--------------------- end //--------------------- num month string function monthstring(num) { if (num === "01") { return "jan"; } else if (num === "02") { return "feb"; } else if (num === "03") { return "mar"; } else if (num === "04") { return "apr"; } else if (num === "05") { return "maj"; } else if (num === "06") { return "jun"; } else if (num === "07") { return "jul"; } else if (num === "08") { return "aug"; } else if (num === "09") { return "sep"; } else if (num === "10") { return "oct"; } else if (num === "11") { return "nov"; } else if (num === "12") { return "dec"; } } //--------------------- end //--------------------- num day of week function daystring(num) { if (num == "1") { return "mon" } else if (num == "2") { return "tue" } else if (num == "3") { return "wed" } else if (num == "4") { return "thu" } else if (num == "5") { return "fri" } else if (num == "6") { return "sat" } else if (num == "0") { return "sun" } } //--------------------- end //--------------------- client call function handleclientload() { gapi.client.setapikey(apikey); checkauth(); } //--------------------- end //--------------------- check auth function checkauth() { gapi.auth.authorize({ client_id: clientid, scope: scopes, immediate: true }, handleauthresult); } //--------------------- end //--------------------- handle result , make call function handleauthresult(authresult) { if (authresult) { makeapicall(); } } //--------------------- end //--------------------- api call function makeapicall() { var today = new date(); //today date gapi.client.load('calendar', 'v3', function () { var request = gapi.client.calendar.events.list({ 'calendarid': useremail, 'timezone': usertimezone, 'singleevents': true, 'timemin': today.toisostring(), //gathers events not happened yet 'maxresults': maxrows, 'orderby': 'starttime' }); request.execute(function (resp) { (var = 0; < resp.items.length; i++) { var li = document.createelement('li'); var item = resp.items[i]; var classes = []; var allday = item.start.date ? true : false; var startdt = allday ? item.start.date : item.start.datetime; var datetime = startdt.split("t"); //split date time var date = datetime[0].split("-"); //split yyyy mm dd var startyear = date[0]; var startmonth = monthstring(date[1]); var startday = date[2]; var startdateiso = new date(startmonth + " " + startday + ", " + startyear + " 00:00:00"); var startdayweek = daystring(startdateiso.getday()); if (allday == true) { //change match needs var str = [ '<font size="4" face="courier">', startdayweek, ' ', startmonth, ' ', startday, ' ', startyear, '</font><font size="5" face="courier"> @ ', item.summary, '</font><br><br>' ]; } else { var time = datetime[1].split(":"); //split hh ss etc... var starthour = ampm(time[0]); var startmin = time[1]; var str = [ //change match needs '<font size="4" face="courier">', startdayweek, ' ', startmonth, ' ', startday, ' ', startyear, ' - ', starthour, ':', startmin, '</font><font size="5" face="courier"> @ ', item.summary, '</font><br><br>' ]; } li.innerhtml = str.join(''); li.setattribute('class', classes.join(' ')); document.getelementbyid('events').appendchild(li); } document.getelementbyid('updated').innerhtml = "updated " + today; document.getelementbyid('calendar').innerhtml = calname; }); }); } //--------------------- end </script> <script src='https://apis.google.com/js/client.js?onload=handleclientload'></script> <div id='content'> <h1 id='calendar' style="color:grey">loading . . . .</h1> <ul id='events'></ul> </div> <p id='updated' style="font-size:12; color:grey">updating . . . . .</p> </body> </html> i editing original post because did not include code originally. subsequently, requested add code. so, here is. thanks
thanks
check if below information set properly:
var clientid = 'your_client_id here'; //choose web app client id, redirect uri , javascript origin set http://localhost var apikey = 'your_apikey_here'; //choose public apikey, ip allowed (leave blank allowed ip boxes in google dev console) var useremail = "your_address@gmail.com"; //your calendar id var usertimezone = "your_time_zone_here"; //example "rome" "los_angeles" ecc... var calname = "your calendar name"; //name of calendar (write want, doesn't matter)
Comments
Post a Comment