如何使用服务帐户和.NET检索Google日历条目 [英] How to retrieve Google calendar entries using service account and.NET
问题描述
使用服务帐户+模拟访问Google日历条目时出现以下错误:
I am getting the following error when using a service account + impersonation to retrieve Google calendar entries:
错误:"access_denied",说明:",Uri:"
Error:"access_denied", Description:"", Uri:""
我可以使用用户帐户和服务帐户流来创建事件(无模拟).我可以同时使用用户帐户和服务帐户流程(使用和不使用模拟)来检索日历.我只能使用用户流来检索日历事件.
I can create events using both user and service account flow (no impersonation). I can retrieve calendars using both user and service account flow (with and without impersonation). I can retrieve calendar events with only user flow.
在相关问题上,我注意到使用oAuth2用户流返回的事件包括我不是参加者的事件,因此我不清楚模拟是否应仅将返回的事件过滤为我是参加者的事件.
On a related matter, I noticed that using the oAuth2 user flow the returned events include those that I am not an attendee, so I am unclear if impersonation should filter returned events to only those that I am an attendee.
这是服务帐户+模拟代码:
Here is the service account + impersonation code:
string serviceAccountEmail = "...@developer.gserviceaccount.com";
var certificate = new X509Certificate2(Server.MapPath("~") + @"\bin\key.p12", "notasecret",
X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(new
ServiceAccountCredential.Initializer(serviceAccountEmail)
{ Scopes = new[] { CalendarService.Scope.Calendar }, User="my email here" }.FromCertificate
(certificate));
BaseClientService.Initializer initializer = new BaseClientService.Initializer();
initializer.HttpClientInitializer = credential;
initializer.ApplicationName = "Google Calendar Sample";
service = new CalendarService(initializer);
IList list = service.CalendarList.List().Execute().Items; // throws error
foreach (CalendarListEntry calendar in list)
DisplayFirstCalendarEvents(calendar);
直接获取日历也会引发相同的错误:
Getting a Calendar directly also throws the same error:
Calendar cal1 = service.Calendars.Get("my personal calendar id").Execute(); //throws same error
推荐答案
我们的Calendar API小组检查了一个,发现以下内容:
Our Calendar API team checked that one and they found out the following:
-
您尝试使用服务帐户628725648769-cda .... 3djjj@developer.gserviceaccount.com访问lbl.gov_7d ... 7oag@group.calendar.google.com的事件.我对么? 看来您在12日使用该服务帐户成功完成了事件插入操作.
You tried to access events of lbl.gov_7d...7oag@group.calendar.google.com using service account 628725648769-cda....3djjj@developer.gserviceaccount.com. Am I correct? It looks like you performed successful event insert operations using that service account on the 12th.
从该帐户到该日历没有失败的请求.
There are no failed requests coming from that account to that calendar.
但是,该服务帐户也于12日访问了lbl.gov_oe10h ..... un9c@group.calendar.google.com,一开始,操作返回404,后返回200(也许有人更改了ACL与此期间的日历?).
However, that service account also accessed lbl.gov_oe10h.....un9c@group.calendar.google.com on the 12th and at the beginning, operations were returning 404, latter 200 (Maybe someone changed ACLs for this calendar in the meantime?).
有什么道理吗?
这篇关于如何使用服务帐户和.NET检索Google日历条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!