Hi everyone,
I need help creating an event for google calendar dealing with the google-api-php-client. Below is my code:
<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_CalendarService.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP Starter Application");
// Visit
https://code.google.com/apis/console?api=plus to generate your
// client id, client secret, and to register your redirect uri.
$client->setClientId('client id');
$client->setClientSecret('client secret');
$client->setRedirectUri('redirect uri');
$client->setDeveloperKey('developer key');
$cal = new Google_CalendarService($client);
if (isset($_GET['logout']))
{
unset($_SESSION['token']);
}
if (isset($_GET['code']))
{
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token']))
{
$client->setAccessToken($_SESSION['token']);
}
// Creates a test event
$event = new Google_Event();
$event->setSummary('Tester');
$event->setLocation('Home');
$start = new Google_EventDateTime();
$start->setDateTime('2013-08-17T16:00:00.000-07:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2013-08-17T17:00:00.000-07:00');
$event->setEnd($end);
$createdEvent = $cal->events->insert('primary', $event); //Returns array not an object
?>
I have a problem with the very bottom insert function. First of all, I am unsure what I need to keep in as a parameter for 'primary'. I have tried keeping my email address for my account but I was not able to succeed in creating the event. I also tried to keep the name of my calendar in this but it didn't succeed. I am having a problem with this and need help.
If you guys could help me with this, I also have other questions dealing with OAuth 2.0 and don't have a good understanding of it and its usage. I will ask those questions later.
Thanks for all the help.