-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getcreds.php
82 lines (57 loc) · 2.18 KB
/
getcreds.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
// Run this from the command line in this directory: (php getcreds.php) and follow the instructions. It will write a file into ~/.credentials
require_once "_config.php" ;
include( SEEDROOT."seedlib/SEEDGoogleService.php" );
if (php_sapi_name() != 'cli') {
throw new Exception('This application must be run on the command line.');
}
$raGoogleParms = array(
'application_name' => "Google Calendar API PHP Quickstart",
// If modifying these scopes, regenerate the credentials at ~/seed_config/calendar-php-quickstart.json
'scopes' => implode(' ', array( Google_Service_Calendar::CALENDAR_READONLY, Google_Service_Calendar::CALENDAR ) ),
// Downloaded from the Google API Console
'client_secret_file' => CATS_CONFIG_DIR."google_client_secret.json",
// Generated by getcreds.php
'credentials_file' => CATS_CONFIG_DIR."calendar-php-quickstart.json",
);
/**
* Expands the home directory alias '~' to the full path.
* @param string $path the path to expand.
* @return string the expanded path.
*/
function expandHomeDirectory($path) {
$homeDirectory = getenv('HOME');
if (empty($homeDirectory)) {
$homeDirectory = getenv('HOMEDRIVE') . getenv('HOMEPATH');
}
return str_replace('~', realpath($homeDirectory), $path);
}
/***********
Replace all of this with CATS_GoogleCalendar
*/
$oG = new SEEDGoogleService( $raGoogleParms, false ); // don't create the Google_Client because the credentials file isn't there yet
//if( !$oG->client ) die( "Could not create Google Client" );
$oG->GetCredentials( true );
$service = new Google_Service_Calendar($oG->client);
// Print the next 10 events on the user's calendar.
$calendarId = 'primary';
$optParams = array(
'maxResults' => 10,
'orderBy' => 'startTime',
'singleEvents' => TRUE,
'timeMin' => date('c'),
);
$results = $service->events->listEvents($calendarId, $optParams);
if (count($results->getItems()) == 0) {
print "No upcoming events found.\n";
} else {
print "Upcoming events:\n";
foreach ($results->getItems() as $event) {
$start = $event->start->dateTime;
if (empty($start)) {
$start = $event->start->date;
}
printf("%s (%s)\n", $event->getSummary(), $start);
}
}
?>