create event on google calendar throw my website

400 views
Skip to first unread message

mohammad al shareif

unread,
Oct 23, 2012, 6:38:33 AM10/23/12
to google-ca...@googlegroups.com
am really stuck and need help..

i create an application that request a permission to manage user calendars 

this the redirect page when user accept my permission
///----------------------
require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_CalendarService.php';
require_once 'src/contrib/Google_Oauth2Service.php';
require_once 'src/contrib/Google_AnalyticsService.php';
session_start();

$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP Starter Application");

// client id, client secret, and to register your redirect uri.
// $client->setClientId('insert_your_oauth2_client_id');
// $client->setClientSecret('insert_your_oauth2_client_secret');
// $client->setRedirectUri('insert_your_oauth2_redirect_uri');
// $client->setDeveloperKey('insert_your_developer_key');
$oauth2 = new Google_Oauth2Service($client);

$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']);
}

if ($client->getAccessToken()) {
  $calList = $cal->calendarList->listCalendarList();
  print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";


$_SESSION['token'] = $client->getAccessToken();
} else {
  $authUrl = $client->createAuthUrl();
  $link= "<a class='login' href='$authUrl'>Connect Me!</a>";
}

if (isset($_GET['code'])) {
  $client->authenticate($_GET['code']);
  $_SESSION['token'] = $client->getAccessToken();
  $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
  header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
  return;
}

if (isset($_SESSION['token'])) {
 $client->setAccessToken($_SESSION['token']);
}

if (isset($_REQUEST['logout'])) {
  unset($_SESSION['token']);
  $client->revokeToken();
}

if ($client->getAccessToken()) {
  $user = $oauth2->userinfo->get();

  // These fields are currently filtered through the PHP sanitize filters.
  $email = filter_var($user['email'], FILTER_SANITIZE_EMAIL);
  $img = filter_var($user['picture'], FILTER_VALIDATE_URL);
  $personMarkup = "$email<div><img src='$img?sz=50'></div>";
print_r($user);
  // The access token may have been updated lazily.
  $_SESSION['token'] = $client->getAccessToken();
} else {
  $authUrl = $client->createAuthUrl();
}
//////------------------------------------------------- 

this code give me the calendar list and user profile and its 100% true

but when i add the following 

$event = new Event();
$start = new EventDateTime();
$start->setDateTime('2012-11-02T10:25:00.000-07:00');
$event->setStart($start);
$end = new EventDateTime();
$end->setDateTime('2012-11-03T10:25:00.000-07:00');
$event->end = $end;

$attendee1 = new EventAttendee();
$attendee1->email = 'mymail...@gmail.com';

$attendees = array($attendee1);
$event->attendees = $attendees;
$createdEvent = $cal->events->insert('mymail...@gmail.com', $event);
//----------------------------- its giv me the following

Fatal error: Class 'Event' not found in /home/roznamti/public_html/new_site/google-api-php-client/google_permission.php on line 91


please what to do..............................

mohammad al shareif

unread,
Oct 23, 2012, 6:45:07 AM10/23/12
to google-ca...@googlegroups.com
and how to get the calendar id for the authenticated user?????
$createdEvent = $cal->events->insert('mymailacco...@gmail.com', $event);
Reply all
Reply to author
Forward
0 new messages