gpt4 book ai didi

php - 创建谷歌日历事件

转载 作者:行者123 更新时间:2023-12-02 05:51:47 25 4
gpt4 key购买 nike

我正在尝试使用下面给出的以下代码创建谷歌日历事件,但我得到类 Event not found 。如何创建新事件。请帮忙

<?php
require_once '../../src/Google_Client.php';
require_once '../../src/contrib/Google_CalendarService.php';
session_start();

$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP Starter Application");

$client->setClientId('');
$client->setClientSecret('');
$client->setRedirectUri('simple.php');
$client->setDeveloperKey('insert_your_developer_key');
$cal = new Google_CalendarService($client);
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}

if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}

if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}

$authUrl = $client->createAuthUrl();
if (!$client->getAccessToken()) {

here am creating the new event

          $event = new Event();
$event->setSummary("test title");
$event->setLocation("test location");
$start = new EventDateTime();
$start->setDateTime('04-03-2012 09:25:00:000 -05:00');
$event->setStart($start);
$end = new EventDateTime();
$end->setDateTime('04-03-2012 10:25:00:000 -05:00');

$createdEvent = $cal->events->insert('primary', $event);

echo $createdEvent->getId();
}

最佳答案

我遇到了完全相同的问题。他们的文档非常不完整。他们的例子中的类名是错误的。这是我开始工作的代码:

$event = new Google_Event();
$event->setSummary('Halloween');
$event->setLocation('The Neighbourhood');
$start = new Google_EventDateTime();
$start->setDateTime('2012-10-31T10:00:00.000-05:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2012-10-31T10:25:00.000-05:00');
$event->setEnd($end);
$createdEvent = $cal->events->insert('[calendar id]', $event); //Returns array not an object

echo $createdEvent->id;

$cal->events->insert 返回一个数组,而不是像示例代码中那样的对象。如果您希望它返回一个对象,您需要在 Google_Client 调用中定义它,如下所示:

$client = new Google_Client(array('use_objects' => true));

关于php - 创建谷歌日历事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13152587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com