【问题标题】:Google Calendar API & PHP Can't Connect / Add EventGoogle Calendar API 和 PHP 无法连接/添加事件
【发布时间】:2014-06-21 05:58:13
【问题描述】:

我正在尝试连接到我们的 Google 日历并添加/编辑活动。我真的不想切换到 Zend 框架,据我所知,没有 ZF 是可能的。我已经安装了客户端库,这是我的代码:

$client = new Google_Client();

$client->setApplicationName("Leah Dawn Calendar Sync");
$client->setClientId('');
$client->setClientSecret('');
$client->setRedirectUri('');
$client->setDeveloperKey('');

$cal = new Google_Service_Calendar($client);

$event = new Google_Service_Calendar_Event();
$event->setSummary('Test Event');
$event->setLocation('My House');

$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2014-06-21T10:00:00.000-05:00');
$event->setStart($start);

$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2014-06-21T10:25:00.000-05:00');
$event->setEnd($end);

$createdEvent = $service->events->insert('myemail@gmail.com', $event); //Returns array not an object
echo $createdEvent->id;

我已经打印出 $event 的结果,并且我确实看到一切都成功连接,并且构建正确,但是最后一行不会执行以实际创建事件。我能找到的所有文档都说这正是如何做到的。有什么想法吗?

【问题讨论】:

    标签: php google-api google-calendar-api google-api-php-client


    【解决方案1】:

    您需要使用 Oauth2 对 myemail@gmail.com 进行身份验证,才能为该帐户创建事件。这里有一个php示例http://cornempire.net/2012/01/08/part-2-oauth2-and-configuring-your-application-with-google/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-06
      • 1970-01-01
      • 2022-01-09
      • 1970-01-01
      • 1970-01-01
      • 2012-09-23
      • 1970-01-01
      相关资源
      最近更新 更多