C# 无法通过API在Google日历中插入新事件

C# 无法通过API在Google日历中插入新事件,c#,google-calendar-api,google-oauth,C#,Google Calendar Api,Google Oauth,我使用Google Calendar v3、OAuth2,我可以登录、查询事件提要,但我无法通过api插入新事件。日历是公开和共享的。以下是我的示例代码: AtomEntry entry = new AtomEntry(); AtomPerson author = new AtomPerson(AtomPersonType.Author); author.Name = "xx"; author.Email = "xx@yahoo.com"; entry.Authors.Add(author

我使用Google Calendar v3、OAuth2,我可以登录、查询事件提要,但我无法通过api插入新事件。日历是公开和共享的。以下是我的示例代码:

AtomEntry entry = new AtomEntry();
AtomPerson author = new AtomPerson(AtomPersonType.Author);
author.Name = "xx";    author.Email = "xx@yahoo.com";
entry.Authors.Add(author);    entry.Title.Text = "Test";
entry.Content.Content = "Test";
calname = "678546u3ua4e1cgc2g1ugku1kg@group.calendar.google.com";
feedUrl = "https://www.googleapis.com/calendar/v3/calendars/{0}/events";
Uri postUri = new Uri(string.Format(feedUrl,calname));
AtomEntry insertedEntry = CalService.Insert(postUri, entry);
我得到这个错误:

[WebException: The remote server returned an error: (401) Unauthorized.]
   System.Net.HttpWebRequest.GetResponse() +6542104
   Google.GData.Client.GDataRequest.Execute() +136

[GDataRequestException: Execution of request failed: https://www.googleapis.com/calendar/v3/calendars/678546u3ua4e1cgc2g1ugku1kg@group.calendar.google.com/events]
Can you please provide a working C# sample with all inclusive instructions on how to insert events from a web application after the user has given permission to use their calendar? Thanks!

检查您为OAuth 2.0访问令牌请求的作用域。要写入日历,您需要与只读不同的权限。请参阅:。您应该确保您请求并获得范围
https://www.googleapis.com/auth/calendar
来自日历所有者。

您正在使用服务帐户吗?如果是,您是否遵循了此链接中提到的域范围委派的步骤