php - Google Calendar V3 service account usage in ZF2 -
php - Google Calendar V3 service account usage in ZF2 -
i aware of fact, not first 1 asking question, have been searching couple of days , cannot seem find solution problem. thing need have application set google business relationship , whenever user completes action application adds event application's google calendar without bothering user consent. need authentication application's business relationship done in code. have done searching , think google server server communication via service business relationship way go. https://developers.google.com/accounts/docs/oauth2serviceaccount
the thing have no thought how set client, access token , phone call api it. far have installed google api using composer:
{ "require": { "php": ">=5.3.3", "zendframework/zendframework": "2.3.*", "dlu/dlutwbootstrap": "dev-master", "google/apiclient": "1.0.*@beta" } } and have created service business relationship google developer console, , obtained client id, email , on. brings code:
$client = new \google_client(); $clientid = '<my id>'; $service_email = '<the email>'; $mymail = '<my other mail>'; $keyfile = './data/<name of file>'; $client->setclientid($clientid); $client->setapplicationname('timesheet'); $key = file_get_contents($keyfile); $client->setassertioncredentials(new google_assertioncredentials( $service_email, array('https://www.googleapis.com/auth/calendar'), $key)); $client->getrequesttoken(); $calendar = new \google_service_calendar($client); $event = new event(); $event->setsummary('appointment'); $event->setlocation('somewhere'); $start = new eventdatetime(); $start->setdatetime('2014-11-05t10:00:00.000-07:00'); $event->setstart($start); $end = new eventdatetime(); $end->setdatetime('2014-11-05t10:25:00.000-07:00'); $event->setend($end); $attendee1 = new eventattendee(); $attendee1->setemail('<email one>'); $attendee2 = new eventattendee(); $attendee2->setemail('<email two>'); $attendees = array($attendee1, $attendee2); $event->attendees = $attendees; $createdevent = $calendar->events->insert('<calendar insert event into>', $event); i appreciate if point out i`m missing , guide me using api properly. give thanks in advance!
best regards,
valentin
at long lastly reply has been found! error in insert call:
$calendar->events->insert('primary', $event); right code bit. need set 'primary' first parameter instead of email.
hope helps someone! :)
php zend-framework2 google-calendar google-api-php-client
Comments
Post a Comment