Php Calendarlist返回带有服务帐户的空结果集
我正在尝试在google日历帐户和google日历API之间建立连接,以便根据google日历包含的事件更新MySQL数据库。似乎我的客户已经设置好了,现在我必须获取日历列表,但我在这里遇到了麻烦 我从quickstart.php中所做的工作以及google文档中所解释的内容中获得了灵感,尝试了一些测试 问题是,当我使用getItems()方法时,我的所有请求都返回一个空结果 我的代码: 我的目标是在获取日历列表时,获取与日历列表中每个日历相关的每个事件,以更新我的数据库。 谢谢Php Calendarlist返回带有服务帐户的空结果集,php,google-api,google-calendar-api,google-api-php-client,service-accounts,Php,Google Api,Google Calendar Api,Google Api Php Client,Service Accounts,我正在尝试在google日历帐户和google日历API之间建立连接,以便根据google日历包含的事件更新MySQL数据库。似乎我的客户已经设置好了,现在我必须获取日历列表,但我在这里遇到了麻烦 我从quickstart.php中所做的工作以及google文档中所解释的内容中获得了灵感,尝试了一些测试 问题是,当我使用getItems()方法时,我的所有请求都返回一个空结果 我的代码: 我的目标是在获取日历列表时,获取与日历列表中每个日历相关的每个事件,以更新我的数据库。 谢谢 G.G您需要记
G.G您需要记住的是,服务帐户不是您自己的。服务帐户是虚拟用户。该用户有自己的google日历帐户、驱动器帐户,可能还有更多 如果你做了一个
$calendar = $service->calendars->get('primary');
echo $calendar->getSummary();
您将看到,实际上您的服务帐户有一个日历。默认情况下,它没有日历列表中的任何内容
如果你想让它访问你的个人谷歌日历,那么你需要访问谷歌日历网站,并与服务帐户的电子邮件地址共享日历。然后它应该能够执行以下操作,确保在设置中记录与它共享的日历的日历id
$calendar = $service->calendars->get('calendarid');
echo $calendar->getSummary();
如果你真的想在日历列表中添加它,你可以添加它
$calendarListEntry = new Google_Service_Calendar_CalendarListEntry();
$calendarListEntry->setId("calendarId");
$createdCalendarListEntry = $service->calendarList->insert($calendarListEntry);
echo $createdCalendarListEntry->getSummary();
服务帐户设置
正如我提到的,服务帐户需要预先授权。您需要转到Google日历网站,并在您希望它能够访问的日历设置下,您需要与它共享日历,如图所示
有用的链接
$calendarListEntry = new Google_Service_Calendar_CalendarListEntry();
$calendarListEntry->setId("calendarId");
$createdCalendarListEntry = $service->calendarList->insert($calendarListEntry);
echo $createdCalendarListEntry->getSummary();