为了账号安全,请及时绑定邮箱和手机立即绑定

Google 日历 - 创建事件说成功但未显示在日历上

Google 日历 - 创建事件说成功但未显示在日历上

PHP
Helenr 2023-04-21 10:05:58
我正在尝试使用 Google 日历 API 创建 Google 日历事件。具体来说,我正在使用服务帐户方法,因为我的应用程序将运行一系列事件以创建并将它们插入到我的 Google 日历中。使用的语言是 PHP。我已经从 gitHub 下载了 PHP 客户端库。 https://github.com/googleapis/google-api-php-client。我的测试代码如下。这成功完成并返回一个长事件 ID。但是,当我尝试将其粘贴到我的浏览器中时,它会将我带到我的日历并显示“找不到请求的事件”。2020 年 5 月 28 日也没有任何显示。谁能让我明白我做错了什么?C:/sites/GoogleCredentials/service-account.json 中的文件是我在 Google Cloud Console 项目下创建的凭据中的服务帐户密钥。require_once('google-calendar/vendor/autoload.php');    putenv('GOOGLE_APPLICATION_CREDENTIALS=C:/sites/GoogleCredentials/service-account.json');    $client = new Google_Client();    $client->useApplicationDefaultCredentials();    $client->addScope(Google_Service_Calendar::CALENDAR_EVENTS);    $service = new Google_Service_Calendar($client);    $event = new Google_Service_Calendar_Event(array(      'summary' => 'Google I/O 2015',      'location' => '800 Howard St., San Francisco, CA 94103',      'description' => 'A chance to hear more about Google\'s developer products.',      'start' => array(        'dateTime' => '2020-05-28T09:00:00',        'timeZone' => 'America/New_York'      ),      'end' => array(        'dateTime' => '2020-05-28T17:00:00',        'timeZone' => 'America/New_York'      )    ));    $calendarId = 'primary';    $event = $service->events->insert($calendarId, $event);    printf('Event created: '.$event->htmlLink);
查看完整描述

1 回答

?
拉丁的传说

TA贡献1789条经验 获得超8个赞

您需要记住服务帐户不是您。服务帐户有自己的谷歌日历帐户。这些事件被插入到它的谷歌日历中,而不是你的。

您应该使用服务帐户电子邮件地址与服务帐户共享您的日历,然后使用日历中的日历 ID 插入。

您也可以保留原样,并确保邀请自己参加服务帐户举办的活动。


查看完整回答
反对 回复 2023-04-21
  • 1 回答
  • 0 关注
  • 87 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信