如何在没有提醒的情况下创建Google日历活动/如何获得服务帐户来模拟用户 [英] How to create a Google Calendar event without a reminder / How to get Service Accounts to impersonate users

查看:64
本文介绍了如何在没有提醒的情况下创建Google日历活动/如何获得服务帐户来模拟用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用PHP库在Google日历中插入一个事件,但是我想创建一个没有提醒的事件(实际上,我想创建一个不是默认值的提醒来简化事件,我会坚持只关闭提醒).

I can insert an event in a Google Calendar using the PHP library, but I want to create the event without a reminder (actually, I want to create it with a reminder that is not the default, but to keep things simple, I'll stick to just turning off the reminder).

这是我关闭提醒的代码:

Here is my code to turn off the reminder:

$reminders = new Google_EventReminders();
$reminders->setUseDefault(false);

$event->setReminders($reminders);

这似乎已成功发送,并且我获得了成功的返回码,但是当我查看日历中的事件时,我看到它仍然具有默认的提醒设置.

This seems to be sent successfully, and I get a successful return code, but when I look at the event in the calendar, I see that it still has the default reminder set.

我到处都在寻找解决方案-我发现的一件事是: http://googleappsdeveloper.blogspot.co.uk /2012/01/calendar-api-v3-best-practices.html 它说:就像日历上的默认提醒一样,这些是针对已登录用户的个人提醒,不会影响其他人对于同一日历或事件的设置."

I have looked everywhere for a solution - and the one thing I found was this: http://googleappsdeveloper.blogspot.co.uk/2012/01/calendar-api-v3-best-practices.html where it says: "Like the default reminders on the calendar, these are personal reminders for the user that is logged in, and will not influence the settings others might have for the same calendar or event."

这使我开始思考用于访问日历的服务帐户.当我查看已插入的事件时,它们都说是由...创建的" my_long_id@developer.gserviceaccount.com.这是否意味着通知仅与开发者帐户相关,而与主要帐户无关?为了支持该理论,我已经能够使用Google API文档中的Try It函数成功插入事件-但这些事件中没有创建者"字段.

That got me thinking about the Service Account that I am using to access the calendar. When I look at the events that have been inserted, they all say 'created by' my_long_id@developer.gserviceaccount.com Does that mean that the notification is only relevant to the developer account, and not to the main account? To support this theory, I have been able to successfully insert an event using the Try It function in the Google API documentation - but these events do not have a 'created by' field in them.

因此,我研究了如何获得一个服务帐户来模拟用户,这让我陷入了困境.这是我尝试过的:

So I researched how to get a Service Account to impersonate a user, and I am stuck. Here is what I have tried:

$client->setAssertionCredentials(new Google_AssertionCredentials(
    SERVICE_ACCOUNT_NAME,
    array('LINK TO auth/calendar', "LINK TO auth/calendar.readonly"),
    $key,
    'notasecret',
    'LINK TO oauth.net/grant_type/jwt/1.0/bearer',
    'my_email_address AT gmail.com'));

(我的编辑工作替代了LINK TO和AT以克服SO限制),但这会产生以下错误:

(my editting to substitute LINK TO and AT to overcome the SO restrictions) But this gives the following error:

Google_AuthException",并显示消息刷新OAuth2令牌时出错,消息:'{ 错误":"access_denied", "error_description":不允许的范围:LINK auth/calendar LINK auth/calendar.readonly"

Google_AuthException' with message 'Error refreshing the OAuth2 token, message: '{ "error" : "access_denied", "error_description" : "Requested scopes not allowed: LINK TO auth/calendar LINK TO auth/calendar.readonly"

(保留最终的电子邮件地址参数可以正常工作-但以开发者作为创建者插入事件)

(Leaving off the final email address parameter works fine - but inserts the event with the development account as the creator)

请问有人知道如何解决此问题(提醒或冒名顶替都可以!)?非常感谢.

Does anyone know how to fix this please (either the reminders or the impersonation will do!)? Many thanks.

推荐答案

我认为使用常规gmail帐户时,创建者"字段是服务帐户的限制-效果不佳.此后,我已切换到Google Apps帐户(用于慈善和教育活动免费),并且创建者"字段不再显示.

I decided that the 'created by' field is a limitation of Service Accounts when working with regular gmail accounts - which don't work very well. I have since switched to a Google Apps account (free for charities and education) and the 'created by' field no longer appears.

这篇关于如何在没有提醒的情况下创建Google日历活动/如何获得服务帐户来模拟用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆