60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/boot.inc';
|
|
|
|
$app = boot();
|
|
|
|
session_start();
|
|
|
|
$client = new Google_Client();
|
|
// $client->setApplicationName("cacao-round-436");
|
|
|
|
$client->setClientId($app['auth']['client_id']);
|
|
$client->setClientSecret($app['auth']['client_secret']);
|
|
$client->setRedirectUri('http://api.audean.com/login.php');
|
|
//$client->setDeveloperKey('insert_your_simple_api_key');
|
|
|
|
// Visit https://code.google.com/apis/console?api=calendar to generate your
|
|
// 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');
|
|
$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'])) {
|
|
echo "<p>Found session<pre>";
|
|
$token = json_decode($_SESSION['token']);
|
|
print_r($token);
|
|
$client->setAccessToken($_SESSION['token']);
|
|
}
|
|
|
|
if ($client->getAccessToken()) {
|
|
$calList = $cal->calendarList->listCalendarList();
|
|
print "<h1>Calendar List</h1><pre>";
|
|
//print_r($calList);
|
|
echo "</pre>\r\n";
|
|
|
|
$items = $cal->events->listEvents("k0vlpg3t9vbqtpe7jfj00h8oo8@group.calendar.google.com");
|
|
var_dump($items);
|
|
foreach ($items as $k => $v) {
|
|
echo "<li>$k:</li>";
|
|
print_r($v);
|
|
}
|
|
//k0vlpg3t9vbqtpe7jfj00h8oo8@group.calendar.google.com
|
|
|
|
|
|
$_SESSION['token'] = $client->getAccessToken();
|
|
} else {
|
|
$authUrl = $client->createAuthUrl();
|
|
print "<a class='login' href='$authUrl'>Connect Me!</a>";
|
|
}
|