php - Google Calendar Events -


i having trouble adding events google calendar. can list events when try add event getting 403 forbidden error. able add events primary, when try one, in case 1 i've mnetion, run 403 forbidden error. here code have:

require_once 'vendor/autoload.php'; define('application_name', 'calendar'); define('credentials_path', 'credentials/calendar.json'); define('secret_path', 'secret.json'); define('scopes', implode(' ', array(google_service_calendar::calendar)));  function getclient() {     $client = new google_client();     $client->setapplicationname(application_name);     $client->setscopes(scopes);     $client->setauthconfigfile(secret_path);     $client->setaccesstype('offline');      $credentials_path = credentials_path;      if (file_exists($credentials_path)) {         $access_token = file_get_contents($credentials_path);     } else {         // $auth_url = $client->createauthurl();         // printf("open following link in browser:\n%s\n", $auth_url);          // print 'enter verification code: ';          // $auth_code = trim(fgets(stdin));          // $access_token = $client->authenticate($auth_code);          // if (!file_exists(dirname($credentials_path))) {             // mkdir(dirname($credentials_path), 0700, true);         // }          // file_put_contents($credentials_path, $access_token);         // printf("credentials saved %s\n", $credentials_path); }     $client->setaccesstoken($access_token);     if ($client->isaccesstokenexpired()) {        $client->refreshtoken($client->getrefreshtoken());        file_put_contents($credentials_path, $client->getaccesstoken());    }     return $client;    }       $client = getclient();     $service = new google_service_calendar($client);      $event = new google_service_calendar_event();    $event->setsummary('appointment');    $event->setlocation('somewhere');    $start = new google_service_calendar_eventdatetime();    $start->setdatetime('2015-04-14t10:00:00.000-07:00');    $event->setstart($start);    $end = new google_service_calendar_eventdatetime();    $end->setdatetime('2015-04-15t10:25:00.000-07:00');    $event->setend($end);    $attendee1 = new google_service_calendar_eventattendee();    $attendee1->setemail('leah@leahdawn.com');     $attendees = array($attendee1);    $event->attendees = $attendees;    $createdevent = $service->events->insert('leah@leahdawn.com', $event);     echo $createdevent->getid(); 

specifically, error 'error calling post https://www.googleapis.com/calendar/v3/calendars/leah%40leahdawn.com/events: (403) forbidden.

any appreciated!

the first parameter of events: insert calendar id, while 'leah@leahdawn.com' valid calendar id. may able see calendar if owner has shared you. doesn't mean owner of said calendar has given permission add events there calendar.

i suggest run calendarlist: get

 $calendarlistentry = $service->calendarlist->get('calendarid');  echo $calendarlistentry->getsummary(); 

this give information calendar if have access.

  {   "kind": "calendar#calendarlistentry",  "etag": "\"1412244000929000\"",  "id": "xxxxx@gmail.com",  "summary": "xxxxx@gmail.com",  "timezone": "europe/copenhagen",  "colorid": "15",  "backgroundcolor": "#9fc6e7",  "foregroundcolor": "#000000",  "selected": true,  "accessrole": "reader",  "defaultreminders": [  ] } 

the thing here "accessrole": "reader", if don't have access more read calendar wont allowed add events.

update: calendarlist : list

try going calendar list page @ bottom run try me. show calendars have access to.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -