simple.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. require_once __DIR__ . '/boot.inc';
  3. $app = boot();
  4. session_start();
  5. $client = new Google_Client();
  6. // $client->setApplicationName("cacao-round-436");
  7. $client->setClientId($app['auth']['client_id']);
  8. $client->setClientSecret($app['auth']['client_secret']);
  9. $client->setRedirectUri('http://api.audean.com/login.php');
  10. //$client->setDeveloperKey('insert_your_simple_api_key');
  11. // Visit https://code.google.com/apis/console?api=calendar to generate your
  12. // client id, client secret, and to register your redirect uri.
  13. // $client->setClientId('insert_your_oauth2_client_id');
  14. // $client->setClientSecret('insert_your_oauth2_client_secret');
  15. // $client->setRedirectUri('insert_your_oauth2_redirect_uri');
  16. // $client->setDeveloperKey('insert_your_developer_key');
  17. $cal = new Google_CalendarService($client);
  18. if (isset($_GET['logout'])) {
  19. unset($_SESSION['token']);
  20. }
  21. if (isset($_GET['code'])) {
  22. $client->authenticate($_GET['code']);
  23. $_SESSION['token'] = $client->getAccessToken();
  24. header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
  25. }
  26. if (isset($_SESSION['token'])) {
  27. echo "<p>Found session<pre>";
  28. $token = json_decode($_SESSION['token']);
  29. print_r($token);
  30. $client->setAccessToken($_SESSION['token']);
  31. }
  32. if ($client->getAccessToken()) {
  33. $calList = $cal->calendarList->listCalendarList();
  34. print "<h1>Calendar List</h1><pre>";
  35. //print_r($calList);
  36. echo "</pre>\r\n";
  37. $items = $cal->events->listEvents("k0vlpg3t9vbqtpe7jfj00h8oo8@group.calendar.google.com");
  38. var_dump($items);
  39. foreach ($items as $k => $v) {
  40. echo "<li>$k:</li>";
  41. print_r($v);
  42. }
  43. //k0vlpg3t9vbqtpe7jfj00h8oo8@group.calendar.google.com
  44. $_SESSION['token'] = $client->getAccessToken();
  45. } else {
  46. $authUrl = $client->createAuthUrl();
  47. print "<a class='login' href='$authUrl'>Connect Me!</a>";
  48. }