[英]Google Calendar API - PHP - Search for single event
我想從我的日歷中搜索並輸出單個事件。 日歷事件包含唯一字符串,例如數字“12345678”(=變量“string”)。 如何在以下代碼中定義此搜索?
<?php
require_once "../google-api/src/Google/autoload.php";
require_once "../google-api/src/Google/Client.php";
require_once "../google-api/src/Google/Service/Calendar.php";
if (isset($_GET['string']) {
$string = $_GET['id'];
$client_id = '[concealed]'; //client of the service account
$Email_address = '[concealed]'; //email id of the service account
$key_file_location = '../google-api/API_Project-[concealed].p12'; //private p12
$client = new Google_Client();
$client->setApplicationName("API Project"); //name of the application
$key = file_get_contents($key_file_location);
// seproate additional scopes with a comma
$scopes ="https://www.googleapis.com/auth/calendar";
$creds = new Google_Auth_AssertionCredentials(
$Email_address,
array($scopes),
$key
);
$client->setAssertionCredentials($creds);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($creds);
}
$service = new Google_Service_Calendar($client);
$calendarList = $service->calendarList->listCalendarList();
$calendarId = '[concealed]'; // Replace this with your calendar ID
$optParams = array(
'singleEvents' => TRUE,
);
try {
$events = $service->events->listEvents($calendarId, $optParams);
} catch( Exception $e ) {
print_r( $e );
}
while(true) {
try {
foreach ($events->getItems() as $event) {
$name = $event->getSummary();
}
} catch( Exception $e ) {
print_r( $e );
}
$pageToken = $events->getNextPageToken();
if ($pageToken) {
$optParams['pageToken'] = $pageToken;
$events = $service->events->listEvents($calendarId, $optParams);
} else {
break;
}
}
}
else{
}
?>
查看events.list的文檔
q
自由文本搜索術語,用於在任何字段中查找與這些術語匹配的事件,但擴展屬性除外。 可選的。
我的PHP有點生疏,但我猜它可能是這樣的
$optParams = array('pageToken' => $pageToken, 'q' => '12345678');
您可以嘗試在底部嘗試我來調試它。
https://www.googleapis.com/calendar/v3/calendars/primary/events?q=hair&key={YOUR_API_KEY}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.