【问题标题】:Google Calendar API v3 quickAdd failGoogle Calendar API v3 quickAdd 失败
【发布时间】:2015-03-21 13:48:44
【问题描述】:

首先,我可以从 Google API 网页添加事件 https://developers.google.com/google-apps/calendar/v3/reference/events/quickAdd#try-it成功输入“calendarId”和“text”参数

但我未能使用“quickAdd”API 通过 PHP 在 Google 日历中添加事件。

require_once "google-api-php-client/src/Google/Client.php";
require_once "google-api-php-client/src/Google/Service/Calendar.php";

// Service Account info
$calName = 'dcm2p5gkf3ge1r7k78f0ko28tc@group.calendar.google.com';
$client_id = '759399732845-j93sis8dktkdj00l3b8mn7gjs3ncf6b9.apps.googleusercontent.com';
$service_account_name = '759399732845-j93sis8dktkdj00l3b8mn7gjs3ncf6b9@developer.gserviceaccount.com';
$key_file_location = 'SMSProject-f14380ee82e4.p12';

$client = new Google_Client();
$client->setApplicationName("SMSProject");

$service = new Google_Service_Calendar($client);

$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials($service_account_name, array('https://www.googleapis.com/auth/calendar'), $key);

$client->setAssertionCredentials($cred);
$createdEvent = $service->events->quickAdd('primary', 'Appointment at Somewhere on January 23rd 10am-10:25am');
echo $createdEvent->getId();

事件ID“g69tq9k7s38rfgit1mpnit9bpk”可以在浏览器中回显,但日历中不显示任何事件

如果我改变了

$createdEvent = $service->events->quickAdd('primary', 'Appointment at Somewhere on January 23rd 10am-10:25am');

$createdEvent = $service->events->quickAdd($calName, 'Appointment at Somewhere on January 23rd 10am-10:25am');

无法生成事件 ID 并显示在错误消息下方

调用 POST https://www.googleapis.com/calendar/v3/calendars/dcm2p5gkf3ge1r7k78f0ko28tc%40group.calendar.google.com/events/quickAdd 时出错:(404) 未找到

我需要使用“quickAdd”而不是“insert”API。如何解决问题?谢谢!

【问题讨论】:

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


    【解决方案1】:

    我遇到了同样的问题,但后来我发现实际上是在日历中为服务帐户 xxxxxxx@developer.gserviceaccount.com 创建事件,而不是我的个人日历。 如果您希望它在您使用的个人日历中创建事件,请进入您的个人日历设置并与您的服务帐户 xxxxxxx@developer.gserviceaccount.com 共享 那么你应该可以使用...

    $createdEvent = $service->events->quickAdd($calName, 'Appointment at Somewhere on January 23rd 10am-10:25am');
    

    ...而不是“主要”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-03
      • 2021-05-19
      • 1970-01-01
      • 1970-01-01
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多