如何模拟用户并使用服务帐户代表用户插入日历?

时间:2019-02-03 22:51:19

标签: laravel-5 google-calendar-api google-api-php-client service-accounts

我正在尝试创建日历,并使用服务帐户与组织的用户共享日历。
我想获得的功能是能够通过我的网站代码(使用服务帐户)和常规的Google日历网络界面管理创建的日历。
所以我想我可以创建一个愚蠢的用户帐户(带有凭据),用服务帐户模拟它,然后创建和共享我的日历,并通过我的Weba pp代码和Google常规用户界面管理事件。
这是正确的进行方式吗?我想念什么吗?
如果我最后的猜测是正确的,如何使用laravel和google-api-clients for PHP来实现?

谢谢您的建议

1 个答案:

答案 0 :(得分:0)

睡觉之后,我意识到无需模仿用户并插入新日历。 要从Officiale Web界面管理服务帐户日历,您只需将其与所有者的权限共享给“哑用户”

类似这样:

//create calendar
$calendar = new Google_Service_Calendar_Calendar();
$calendar->setSummary('calendarname');
$calendar->setTimeZone('Europe/Berlin');
$service = new Google_Service_Calendar();
$createdCalendar = $service->calendars->insert($calendar);

//share it with your dumb user 
$rule = new Google_Service_Calendar_AclRule();
$scope = new Google_Service_Calendar_AclRuleScope();
$scope->setType("user");
$scope->setValue('dumbuser@organization.com');
$rule->setScope($scope);
$rule->setRole("owner");
$createdRule = $service->acl->insert(createdCalendar->getId(), $rule);

因此,我的问题目前已解决,我仍在思考的唯一问题是如何使用服务帐户凭据模拟用户?好吧,我会考虑它何时会真正有用