Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ...
- private function getMinMaxOfDay($min=true) {
- $date = new DateTime(date('c'));
- $today = date('j');
- if($min) {
- $today -= 1;
- $date->modify("-$today day");
- }else {
- $maxDay = date('t') - $today;
- $date->modify("$maxDay day");
- }
- return $date->format('c');
- }
- public function actionDemo() {
- $client = new \Google_Client();
- $client->setApplicationName('Demo Calendar Service');
- $clientEmail = 'calendar@demo.iam.gserviceaccount.com';
- $privateKey = join('/', [Yii::getPathOfAlias('application.config'),
- 'Demo123.json']);
- $scopes = 'https://www.googleapis.com/auth/calendar.readonly';
- putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $privateKey);
- $client->addScope(\Google_Service_Calendar::CALENDAR_READONLY);
- $client->useApplicationDefaultCredentials();
- $client->setSubject($clientEmail);
- $client->setAuthConfig($privateKey);
- $service = new Google_Service_Calendar($client);
- $optParams = [
- 'maxResults' => 10,
- 'orderBy' => 'startTime',
- 'singleEvents' => true,
- 'timeMax' => $this->getMinMaxOfDay(false),
- 'timeMin' => $this->getMinMaxOfDay(),
- ];
- $calendar = $service->events->listEvents('primary', $optParams);
- print_r($calendar->getItems());
- }
- ...
Add Comment
Please, Sign In to add comment