2

我有一个工作脚本,它正在我的谷歌日历中创建事件 - 使用 google-api-php-client。我正在尝试使用以下代码向它创建的每个事件添加一个小工具:

require_once "google-api-php-client/src/Google_Client.php";

require_once "google-api-php-client/src/contrib/Google_CalendarService.php";

define('CLIENT_ID', 'xxx...');

define('SERVICE_ACCOUNT_NAME', 'xxx...');

define('KEY_FILE', 'xxx...');

$client = new Google_Client();

$client->setApplicationName("WEB ACCTION");

$key = file_get_contents(KEY_FILE);

$client->setAssertionCredentials(new Google_AssertionCredentials(SERVICE_ACCOUNT_NAME,'xxx...',$key));

$client->setClientId(CLIENT_ID);

$service = new Google_CalendarService($client);

$event = new Google_Event();

$event->setSummary($variable1);

$event->setLocation($variable2 . ", " . $variable3);

$start = new Google_EventDateTime();

$start->setDateTime(date(DATE_ATOM, strtotime($variable4) + $time_offset));

$event->setStart($start);

$end = new Google_EventDateTime();

$end->setDateTime(date(DATE_ATOM, strtotime($variable5) + $time_offset));

$event->setEnd($end);

//The not working section

//$gadget = new Google_EventGadget();           
//$gadget->setIconLink('xxx...');
//$gadget->setTitle('xxx...');
//$gadget->setHeight('xxx...');
//$gadget->setWidth('xxx...');
//$gadget->setLink('xxx...');
//$gadget->setType('xxx...');
//$gadget->setDisplay('xxx...');
//$event->setGadget($gadget);

$createdEvent = $service->events->insert($g_calendar , $event);

不幸的是 - 我无法让它工作,我无法找到有关使用 google-api-php-client 创建小工具的任何信息。该库包含一个Google_EventGadget类和setGadget函数,但没有关于如何使用它们的信息。有人可以帮我吗?

4

1 回答 1

0

我找到了解决方案 - google-api-php-client 仅支持小工具及其图标的认证链接。直到我使用https://www...链接,它才起作用。

即使我用于测试的主机没有安全证书,它也能正常工作。

$gadget->setIconLink('https://www...');

$gadget->setLink('https://www....');

$gadget->setDisplay('chip');

$gadget->setWidth('400');

$gadget->setHeight('100');

$event->setGadget($gadget);

$createdEvent = $service->events->insert($g_calendar , $event);

希望它能节省一些时间!

于 2013-01-07T23:19:17.123 回答