【问题标题】:How to retrieve Google calendar entries using service account and.NET如何使用服务帐户和 .NET 检索 Google 日历条目
【发布时间】:2013-11-12 22:11:21
【问题描述】:

使用服务帐户 + 模拟检索 Google 日历条目时出现以下错误:

错误:“access_denied”,描述:“”,Uri:“”

我可以使用用户和服务帐户流创建事件(无模拟)。我可以使用用户和服务帐户流(有和没有模拟)检索日历。我可以仅使用用户流检索日历事件。

在相关问题上,我注意到使用 oAuth2 用户流返回的事件包括我不是与会者的事件,因此我不清楚模拟是否应将返回的事件过滤到仅我是与会者的事件。

这里是服务帐号+模拟代码:

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);

直接获取日历也会抛出同样的错误:

Calendar cal1 = service.Calendars.Get("my personal calendar id").Execute();  //throws same error

【问题讨论】:

    标签: c# .net google-calendar-api google-api-dotnet-client


    【解决方案1】:

    我们的日历 API 团队检查了那个,他们发现了以下内容:

    1. 您尝试使用服务帐户 628725648769-cda....3djjj@developer.gserviceaccount.com 访问 lbl.gov_7d...7oag@group.calendar.google.com 的事件。我对么? 您似乎在 12 日使用该服务帐号成功执行了事件插入操作。

    2. 没有从该帐户发送到该日历的失败请求。

    3. 但是,该服务帐户也在 12 日访问了 lbl.gov_oe10h.....un9c@group.calendar.google.com,一开始,操作返回 404,后返回 200(可能有人更改了 ACL同时为这个日历?)。

    有意义吗?

    【讨论】:

      猜你喜欢
      • 2014-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      相关资源
      最近更新 更多