使用 API 从 Google 日历中检索事件

Posted

技术标签:

【中文标题】使用 API 从 Google 日历中检索事件【英文标题】:Retrieve Events from Google Calendar Using API 【发布时间】:2014-04-22 17:29:03 【问题描述】:

我是 Google Calendar API 和 php 的新手,我似乎不知道如何实现我想做的事情。基本上,我想从带有 webapps098@gmail.com 的 calendarID 的谷歌日历中检索事件。 我当前的代码类似于

require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_BooksService.php';
require_once 'google-api-php-client/src/contrib/Google_CalendarService.php';

$client = new Google_Client();
$client->setUseObjects(true);
$service = new Google_CalendarService($client);

try
    $events = $service->calendars->get('webapps098@gmail.com');
    print_r($events);
catch(Exception $e)
    echo $e;
    

我收到错误消息:

异常“Google_ServiceException”和消息“调用 GET 时出错” https://www.googleapis.com/calendar/v3/calendars/webapps098@gmail.com: (401) 需要登录 C:\xampp\htdocs\Test\google-api-php-client\src\io\Google_REST.php:66 堆栈跟踪:#0 C:\xampp\htdocs\Test\google-api-php-client\src\io\Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 C:\xampp\htdocs\Test\google-api-php-client\src\service\Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest)) #2 C:\xampp\htdocs\Test\google-api-php-client\src\contrib\Google_CalendarService.php(300): Google_ServiceResource->__call('get', Array) #3 C:\xampp\htdocs\Test\refreshscript.php(10): Google_CalendarsServiceResource->get('webapps098@gmai...') #4 main

我希望任何人都可以提供帮助!抱歉,感谢您的理解。

【问题讨论】:

【参考方案1】:

您正在尝试获取需要具有 oAuth 令牌的东西。如果您只是从公共日历中提取事件,我建议您使用 Google 提要而不是 Google API。

【讨论】:

以上是关于使用 API 从 Google 日历中检索事件的主要内容,如果未能解决你的问题,请参考以下文章

Google Calendar API 出错 - 添加日历事件时需要 401 登录

如何使用 android 使用日历 API 在谷歌日历上添加事件?

Google 日历 API 在公共日历中插入事件时返回错误 401“需要登录”

使用 Google 日历在 Fullcalendar 中选择事件

如何检索 Google 日历活动的扩展属性?

Google Calendar API 在 Pod 更新后向日历插入事件时会出现 404。