【问题标题】:Using Google calendar API to create an event, but nothing appear in my Google calendar使用 Google 日历 API 创建事件,但我的 Google 日历中没有显示任何内容
【发布时间】:2014-04-02 09:48:02
【问题描述】:

我正在使用此代码将事件添加到我的日历:

<?php
set_include_path( get_include_path() . PATH_SEPARATOR . 'lib/google-api-php-client-master/src' );
require_once 'lib/google-api-php-client-master/src/Google/Client.php';
require_once 'lib/google-api-php-client-master/src/Google/Service/Calendar.php';
$client = new Google_Client();
$client->setApplicationName("Calendar");
$scopes = array('https://www.googleapis.com/auth/prediction', 'https://www.googleapis.com/auth/calendar');
$service_account_name='xxxx@developer.gserviceaccount.com';
$key_file_location='lib/myKey.p12';
$key = file_get_contents($key_file_location);
$auth_credentials = new Google_Auth_AssertionCredentials($service_account_name, $scopes, $key);
$client->setAssertionCredentials($auth_credentials);
$client->setClientId('xxxx.apps.googleusercontent.com');
$service = new Google_Service_Calendar($client);

try { 

$event = new Google_Service_Calendar_Event();
$event->setSummary('Halloween');
$event->setLocation('The Neighbourhood');
$event->setDescription('rien');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2014-04-02T10:00:00.000-07:00');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2014-04-03T10:25:00.000-07:00');
$event->setEnd($end);




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

echo $createdEvent->getId();
}
catch (Exception $ex)
{
    die($ex->getMessage());
}
?>

我得到了事件 ID,它被打印出来了,但是当我在浏览器中查看我的日历时 - 什么都没有。

【问题讨论】:

    标签: google-calendar-api


    【解决方案1】:

    它正在服务帐户的日历中创建活动,请查看我的回答 here

    【讨论】:

      猜你喜欢
      • 2019-10-24
      • 2017-01-24
      • 2014-03-24
      • 1970-01-01
      • 2022-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多