英文:
Google Calendar API insert event as another user calendar, reply to email is wrong
问题
我们设置了这样一个方案,在此过程中,Google管理员将一次性集成到他们的Workspace中,以允许Google日历与整个Workspace集成,从而允许所有用户在其Workspace中创建/更新事件,而无需让每个用户都自行进行集成。
https://developers.google.com/calendar/api/v3/reference/events/insert
我们使用的范围为https://www.googleapis.com/auth/calendar.events
因此,我们通过传递用户的日历ID来在用户的日历中创建事件,然后会向事件添加参与者。
除了在使用API端点创建事件时遇到一个主要问题外,一切都正常运作。问题是,邮件发送给参与者时,回复地址总是原始管理员添加集成时的邮件地址,因此人们在回复日历邀请时也会将邮件发送给管理员。
我们已经在API中尝试了一切可能的方法,但回复地址始终是管理员的电子邮件地址,而我们希望它与发件人的电子邮件地址相同。
英文:
We have a setup where a Google Administrator will integrate once to their Workspace to allow Google Calendar integration with their whole workspace, allowing all users to create/update events across their workspace, without having to get each user to integrate themselves.
https://developers.google.com/calendar/api/v3/reference/events/insert
Scope we using https://www.googleapis.com/auth/calendar.events
So we create events on in users calendars, by passing in a Calendar ID for the user, and then will add attendees to the event.
Everything works normal, except when using the API endpoint to create an event, we are having 1 major problem where the From address, is ok but the Reply To address in the email sent to attendees for some reason always is the email of the original admin who added the integration, so people are doing email reply all to the to calendar invitations and end up also sending the emails to the admin.
We have tried everything possible in API , but it reply to address is always the admin email, and we expect it to be the same as the from: email
答案1
得分: 1
根据您提供的详细信息,我猜测应用程序正在使用的凭据是 OAuth 2客户端ID
。我进行了一些测试,作为管理员,我创建了事件,并在请求中将其他用户的电子邮件地址添加为组织者,但得到了您报告的相同结果。
我在官方文档中找不到为什么会发生这种情况的原因,我认为这是可以预期的,因为我在Google日历UI中手动测试创建事件时也得到了相同的结果。您可以在此处提交关于此行为的反馈意见 here。
我找到的唯一解决方案是使用服务帐号进行模拟操作,这意味着服务帐号代表用户(例如组织中的任何用户)进行操作,当应用程序在Google日历中创建事件时,它等同于用户自己创建事件。
要设置模拟操作,您需要:
-
创建服务帐号并在Google Cloud控制台中创建服务帐号密钥。
-
在您的管理控制台中为服务帐号所需的所有范围授权:
- 安全性 > API控制 > 域广泛委托。
-
修改您的代码以使用服务帐号密钥进行身份验证。
我不知道您使用的编程语言,但我使用Python进行了这个测试,reply-to
地址与from
电子邮件地址匹配,如果您需要示例,请告诉我,但您还可以在以下文档中找到其他编程语言的示例。
参考资料
英文:
Based on the details you shared, I would guess that the credentials the app is using is OAuth 2 client ID
. I did some tests, as an admin I created the event and added in the request the other user's email address as the organizer but got the same result you are reporting.
I could not find in the official documentation why this happens, I would say it is expected as I tested creating the event manually in the Google Calendar UI and got the same result. You can submit your feedback about this behavior here.
The only solution I found is doing impersonation with a service account, this means that the service account acts on behalf of the user (e.g. any user in the organization) and when the app creates events in Google Calendar, it is equivalent to when the user itself creates the event.
To set up impersonation you need to:
-
Create a service account and create a service account key in the Google Cloud console.
-
Authorize all the scopes the service account needs in your Admin console:
- Security > API Controls > Domain wide delegation.
-
Modify your code to authenticate using the service account key.
I don't know what programming language you're using but I did this test with Python and the reply-to
address matches with the from
email address, if you need the sample let me know but you can also find samples with other programming language in the documentation below.
References
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论