Advertisement
Guest User

Untitled

a guest
Sep 11th, 2013
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. <?php
  2. require_once 'google-api-php-client/src/Google_Client.php';
  3. require_once 'google-api-php-client/src/contrib/Google_CalendarService.php';
  4. session_start();
  5.  
  6.  
  7. $client = new Google_Client();
  8. $client->setApplicationName("Google Calendar PHP Starter Application");
  9. $client->setClientId('###');
  10. $client->setClientSecret('###');
  11. $client->setRedirectUri('###');
  12. $client->setDeveloperKey('###');
  13. $cal = new Google_CalendarService($client);
  14.  
  15. if (isset($_GET['logout'])) {
  16. unset($_SESSION['token']);
  17. }
  18.  
  19. if (isset($_GET['code'])) {
  20. $client->authenticate($_GET['code']);
  21. $_SESSION['token'] = $client->getAccessToken();
  22. header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
  23. }
  24.  
  25. if (isset($_SESSION['token'])) {
  26. $client->setAccessToken($_SESSION['token']);
  27. }
  28.  
  29. $authUrl = $client->createAuthUrl();
  30.  
  31. if ($client->getAccessToken()){
  32.  
  33. $event = new Google_Event();
  34.  
  35. $event->setSummary('Halloween');
  36. $event->setLocation('The Neighbourhood');
  37. $start = new Google_EventDateTime();
  38. $start->setDateTime('2013-09-11T10:00:00.000-05:00');
  39. $event->setStart($start);
  40. $end = new Google_EventDateTime();
  41. $end->setDateTime('2013-09-11T10:25:00.000-05:00');
  42. $event->setEnd($end);
  43. $createdEvent = $cal->events->insert('###', $event);
  44.  
  45. echo $createdEvent->getId();
  46. }
  47.  
  48. else {
  49. $authURL = $client->createAuthURL();
  50. echo $authURL;
  51. }
  52.  
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement