当前位置: 首页 > 知识库问答 >
问题:

404在C#中访问公共Google API日历v3时出错

白青青
2023-03-14

尝试访问公共日历时,我收到以下错误:

An unhandled exception of type 'Google.GoogleApiException' occurred in mscorlib.dll
Google.Apis.Requests.RequestError
Not Found [404]
Errors [
Message[Not Found] Location[ - ] Reason[notFound] Domain[global]

当我使用简单的获取 HTTP 调用谷歌 API 时,我的 API 密钥和日历 ID 可以正常工作。

我用这里的博文创建了这个代码:https://www.daimto.com/public-google-calendars-with-c/

我的代码

class Program
{
    static void Main(string[] args)
    {

        var service = new CalendarService(new BaseClientService.Initializer()
        {
            ApiKey = "My API Key From Google Console",
            ApplicationName = "I put my API Key name from Google Console here",

        });

        var events = service.Events.List("thefirstacademy.org_2ldo8np1v5tr1qlpbho6ip6tog%40group.calendar.google.com").Execute();

        foreach (var myEvent in events.Items)
        {
            Console.WriteLine(string.Format("Event: {0} Start: {1} End: {2}", myEvent.Summary, myEvent.Start.DateTime.ToString(), myEvent.End.DateTime.ToString()));
        }
    }
}

共有1个答案

相俊迈
2023-03-14

我找到了答案。使用的日历 ID 必须在“group.calendar.google.com”部分之前有一个 @ 符号。尽管该 ID 在 GET HTTP 中有效,但在 C# 中的谷歌.API.日历.V3 中也不起作用。

 类似资料:
  • 我试图创建一个日历使用谷歌日历API v3,如果它还不存在。我的实现成功地检索了我的所有日历和事件,并可以更改日历,但我正在努力添加一个新日历。为了尝试为用户添加新日历,我会这样做: 生成的请求: RequestError: 奇怪的是,在https://www.googleapis.com/calendar/v3/users/me/calendarlist?alt=json&prettyprint

  • 如果有人分享了他们的谷歌日历(例如,用一个小部件显示在网页上),那么我就可以得到日历,例如:p75ig3ni1smg4267qg0j0nhodc@group.calendar.google.com 我想编写一个Alexa应用程序(在NodeJS中)来提供该日历中的信息。(我使用此示例作为模型:https://developers.google.com/google-apps/calendar/qu

  • 我正在尝试使用谷歌API的v3从客户的公共日历中获取事件列表。我在API Explorer中输入了日历ID,得到了一个肯定的结果: 为了创建 API 密钥,我在 Google 开发者控制台中创建了一个项目,并创建了一个公共 API 访问密钥 (API 我看到的所有回复都表明,您需要确保Google Calendar API已打开,而且它确实已打开(默认情况下也是打开的)。我在这里错过了什么?

  • 假设我被授予访问其他用户日历的权限。我可以在Google calendar web UI的“其他日历”下成功地查看该日历。 该日历可以通过Caldav访问吗?如果是,怎么做? 我的CalDAV客户端开始查看https://apidata.googleusercontent.com/CalDAV/v2,并通过oauth2进行身份验证。它遵循当前用户主体URL,并从那里到日历主页集。在calendar

  • 我想使用谷歌的REST API访问公共日历。 Google的日历API建议我需要OAuth令牌才能访问日历: https://developers.google.com/google-apps/calendar/auth 然而,我正在访问一个公共日历,并且正在服务器上执行此操作,因此不能/不应该要求用户进行身份验证。 我使用node.jsapi: 这将返回“您的客户端发出了一个格式错误或非法的请求

  • 我正在阅读以前Office 365共享日历的问题 使用Oauth进行身份验证的用户现在可以访问共享日历了吗? 基本上,我尝试使用“OAuth2客户端凭据流”来实现一个服务,但是我希望只有当日历与使用rest api调用的特定用户共享时才能访问该日历:https://outlook.office365.com/api/v1.0/Users/"电子邮件id/calendar groups/" "其他日