0
感謝您的時間。我已經找到了關於如何爲公共日曆執行此操作的文檔,但我需要它來提供不會與世界共享的日曆。需要從日曆API中讀取而不公開日曆
這是我的代碼:
include(__DIR__ . '/composer/vendor/google/apiclient/autoload.php');
$client_email = '[email protected]';
$private_key = file_get_contents('/home/serverSecret.json');
$scopes = array(Google_Service_Drive::DRIVE_METADATA_READONLY);
$credentials = new Google_Auth_AssertionCredentials($client_email, $scopes, $private_key);
$client = new Google_Client();
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired())
{
$client->getAuth()->refreshTokenWithAssertion();
}
$client->setApplicationName("A Calendar");
$cal = new Google_Service_Calendar($client);
$calendarId = '[email protected]';
$params = array('singleEvents' => true, 'orderBy' => 'startTime', 'timeMin' => date(DateTime::ATOM), 'maxResults' => 7);
$events = $cal->events->listEvents($calendarId, $params);
$calTimeZone = $events->timeZone;
date_default_timezone_set($calTimeZone);
foreach ($events->getItems() as $event)
{
// Get the timings
$eventDateStr = $event->start->dateTime;
if(empty($eventDateStr)) { $eventDateStr = $event->start->date; } // Handle all-day events
$temp_timezone = $event->start->timeZone;
// Timezone override if applicable
if (!empty($temp_timezone)) { $timezone = new DateTimeZone($temp_timezone); }
else { $timezone = new DateTimeZone($calTimeZone); }
// Set up the timings
$eventdate = new DateTime($eventDateStr,$timezone);
$link = $event->htmlLink;
$TZlink = $link . "&ctz=" . $calTimeZone;
$newmonth = $eventdate->format("M");
$newday = $eventdate->format("j");
?>
<div class="event-container">
<div class="eventDate">
<span class="month"><?=$newmonth?></span>
<br />
<span class="day"><?=$newday?></span>
<span class="dayTrail"></span>
</div>
<div class="eventBody">
<a href="<?=$TZlink?>"><?=$event->summary?></a>
</div>
</div>
<?php
}
?>
上述工作,當我使用客戶端密鑰,但不是當日歷是由私人公共日曆使用它。我需要知道如何對私人日曆進行身份驗證。