繁体   English   中英

Google Calendar API - PHP - 搜索单个活动

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM