View difference between Paste ID: QJ7WTQfq and WQ8BqtFL
SHOW: | | - or go back to the newest paste.
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
    $client = new Google_Client();
7
    $client->setApplicationName("Google Calendar PHP Starter Application");
8
    $client->setClientId('###');
9
    $client->setClientSecret('###');
10
    $client->setRedirectUri('http://test.mydomain.com/index.php'); //redirect works now! =)
11
    $client->setDeveloperKey('###');
12
    $cal = new Google_CalendarService($client);
13
14
if (isset($_GET['logout'])) {
15
    unset($_SESSION['token']);
16
}
17
18
if (isset($_GET['code'])) {
19
	echo "got the code"; //Gets here 2nd
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
	echo "got the token"; 
27
    $client->setAccessToken($_SESSION['token']);
28
}
29
30
if ($client->getAccessToken()){
31
		echo "get the token";
32
        $event = new Google_Event();
33
        $event->setSummary('Halloween');
34
        $event->setLocation('The Neighbourhood');
35
        $start = new Google_EventDateTime();
36
        $start->setDateTime('2013-9-29T10:00:00.000-05:00');
37
        $event->setStart($start);
38
        $end = new Google_EventDateTime();
39
        $end->setDateTime('2013-9-29T10:25:00.000-05:00');
40
        $event->setEnd($end);
41-
        $createdEvent = $cal->events->insert('t26isl72cpl3rk3o5jbhhl493g@group.calendar.google.com', $event);
41+
        $createdEvent = $cal->events->insert('###', $event);
42
}
43
44
else {
45
		echo "else<br />"; //gets here first
46
        $authURL = $client->createAuthURL();
47
        echo $authURL;
48
}
49
50
?>