Google Api 用户代码未处理的异常:请求错误

Google Api Exception Unhandled by User Code: Request Error

本地 VS2015 ASP.NET 4.5 应用程序在我尝试从我的 Google 日历请求事件时抛出此异常:

Google.GoogleApiException was unhandled by user code
HResult=-2146233088 Message=Google.Apis.Requests.RequestError Not Found [404] Errors [ Message[Not Found] Location[ - ] Reason[notFound] Domain[global] ]

我的应用程序访问 primary 日历事件时没有大惊小怪,但在我尝试指定特定 calID 时出现问题。是否有针对此错误的相对简单的补救措施?

我仔细听从了 Google Calendar API v3 Access Not Configured 等其他帖子的建议,关于在设置菜单下从我的日历 ID 中删除 @group.calendar.google.com 扩展名。我使用了 OAuth,一个本机应用程序的客户端 ID,并启用了我的 localhost 作为重定向 URI。

        UserCredential credential;

        using (var stream =
            new FileStream(@"c:\Authentication\my_client_secret.json", FileMode.Open, FileAccess.Read))
        {
            string credPath = System.Environment.GetFolderPath(
                System.Environment.SpecialFolder.Personal);
            credPath = Path.Combine(credPath, ".credentials");

            credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                Scopes,
                "user",
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;
        }

        // Create Google Calendar API service.
        var service = new CalendarService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = ApplicationName,
        });

        // Define parameters of request
        string calID = "{MY_SECRET_CAL_ID}";
        EventsResource.ListRequest request = service.Events.List(calID.ToString());
        request.TimeMin = DateTime.Now;
        request.ShowDeleted = false;
        request.SingleEvents = true;
        request.MaxResults = 10;
        request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

        // List events.
        Events events = request.Execute();

堆栈跟踪:

ServiceName=calendar Source=Google.Apis StackTrace: at Google.Apis.Requests.ClientServiceRequest`1.Execute() in c:\code\github\google-api-dotnet-client\Tools\Google.Apis.Release\bin\Release.9.2\default\Src\GoogleApis\Apis\Requests\ClientServiceRequest.cs:line 93 at ConferenceTracker.North.LoadCalendar() in C:\Users\MYUSER\Desktop\NewConferenceTracker\ConferenceTracker\ConferenceTracker\North.aspx.cs:line 132 at ConferenceTracker.North.RunStartupRoutine() in C:\Users\MYUSER\Desktop\NewConferenceTracker\ConferenceTracker\ConferenceTracker\North.aspx.cs:line 94 at ConferenceTracker.North.Page_Load(Object sender, EventArgs e) in C:\Users\MYUSER\Desktop\NewConferenceTracker\ConferenceTracker\ConferenceTracker\North.aspx.cs:line 64 at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:

经过数小时的反复试验,我尝试提交 request 并添加 @group.calendar.google.com。与我之前研究的预期相反,请求得到了正确处理,我可以从我想要的特定日历中查看事件。因此,事实证明,@group.calendar.google.com 实际上是 {MY_SECRET_CAL_ID}!

中包含的重要元素