Mainos / Advertisement:

Google calendar api

From Taisto
Jump to navigation Jump to search

{{#allow-groups:sysop}}

<?php
session_start();
require_once '/var/www/src/Google_Client.php';
require_once '/var/www/src/contrib/Google_AnalyticsService.php';
$scriptUri = "https://www.googleapis.com/calendar/v3/calendars/15fv1dumutu96fvlfdaee0gduk%40group.calendar.go$
$client = new Google_Client();
$client->setAccessType('online'); // default: offline
$client->setApplicationName('kalenteri');
$client->setClientId('638761389690-q8tb5430b6f2fp8dcgfp4odk78bmnece.apps.googleusercontent.com');
$client->setClientSecret('-CUZlv0DJLMPiKAiw6XFvLYC');
$client->setRedirectUri($scriptUri);
$client->setDeveloperKey('AIzaSyD-qvvRkkKn8D6367oS4xgTyM9dnLhqfmY'); // API key
// $service implements the client interface, has to be set before auth call
$service = new Google_AnalyticsService($client);
if (isset($_GET['logout'])) { // logout: destroy token
   unset($_SESSION['token']);
       die('Logged out.');
}
if (isset($_GET['code'])) { // we received the positive auth callback, get the token and store it in session
   $client->authenticate();
   $_SESSION['token'] = $client->getAccessToken();
}
if (isset($_SESSION['token'])) { // extract token from session and configure client
   $token = $_SESSION['token'];
   $client->setAccessToken($token);
}
if (!$client->getAccessToken()) { // auth call to google
   $authUrl = $client->createAuthUrl();
   header("Location: ".$authUrl);
   die;
}
echo 'Hello, world.';
Mainos / Advertisement: