How to display all google calendar events and add new event using php -
How to display all google calendar events and add new event using php -
i want write 1 php script can create event on google calendar , can fetch list of event on 1 particular google calendar account.
i saw documentation , confusing , not clear. on stack on flow there different technic no 1 explain clearly.
i have created 1 project google console , generate public api access , using code fetch list of calendar event got error "fatal error: uncaught exception 'google_service_exception' message 'error calling https://www.googleapis.com/calendar/v3/calendars.../google_agenda/src/google/http/rest.php on line 110"
also using updated library https://github.com/google/google-api-php-client
and code
error_reporting(e_all); ini_set("display_errors", 1); require_once('google_agenda/src/google/autoload.php'); date_default_timezone_set('europe/paris'); $client = new google_client(); $client->setapplicationname("my_app"); //don't think matters $client->setdeveloperkey('sdsfdfdddssffdfdfdfdn_dgdgs'); //get @ at developers.google.com $cal = new google_service_calendar($client); $calendarid = 'test@test.com'; $params = array( 'singleevents' => true, 'orderby' => 'starttime', 'timemin' => date(datetime::atom),//only pull events starting today 'maxresults' => 2 //only utilize if want limit number //of events displayed ); $events = $cal->events->listevents($calendarid, $params); foreach ($events->getitems() $event) { //convert date month , day $eventdatestr = $event->start->datetime; if(empty($eventdatestr)) { // it's day event $eventdatestr = $event->start->date; } $temp_timezone = $event->start->timezone; if (!empty($temp_timezone)) { $timezone = new datetimezone($temp_timezone); //get time zone //set default timezone in case events don't have 1 } else { $timezone = new datetimezone("europe/paris"); } $eventdate = new datetime($eventdatestr,$timezone); $newmonth = $eventdate->format("m");//convert regular event date legible month $newday = $eventdate->format("j");//convert regular event date legible day ?> <div class="event-container"> <div class="eventdate"> <span class="month"><?php echo $newmonth; ?></span><br /> <span class="day"><?php echo $newday; ?></span><span class="daytrail"></span> </div> <div class="eventbody"> <a href="<?php echo $event->htmllink; //event links standardized, no need add together junk end ?>"> <?php echo $event->summary; //summary = title ?> </a> </div> </div>
any help appreciated looking forwards response give thanks you
this php quick guide should started on events listing: https://developers.google.com/google-apps/calendar/quickstart/php
php google-api google-calendar php-5.3
Comments
Post a Comment