【问题标题】:Error 404 when creating a calendar with Google Calendar Api v3 using c# .net使用 c# .net 使用 Google Calendar Api v3 创建日历时出现错误 404
【发布时间】:2017-12-23 18:30:07
【问题描述】:

我正在尝试使用 Google Calendar API v3 创建日历(如果它尚不存在)。我的实现成功地检索了我的所有日​​历和事件,并且可以更改日历,但我正在努力添加新日历。这是我为了尝试为用户添加新日历所做的:

...
var calendarService = new CalendarService(_authenticator);
var calendarId = "com.somedomain.somename.1234"; // Some random ID
try {
    calendarManager.GetCalendar(calendarId); // No calandar found
} catch(GoogleCalandarServiceProxyException e){
    // Ok, so far so good, calendar not found (that is correct) and I am here
    var someCalendar = new Google.Apis.Calendar.v3.Data.CalendarListEntry {
        Summary = "Some summary!",
        Description = "A calendar descr.",
        AccessRole = "writer",
        BackgroundColor = "#E7323C",
        Id = calendarId
    };
    calendarService.CalendarList.Insert(someCalendar).Fetch(); // Fetch to execute
}

请求生成:

insert @ https://www.googleapis.com/calendar/v3/users/me/calendarList?alt=json&prettyPrint=true

请求错误:

Google.Apis.Request.RequestErrorNotFound[404]Errors [Message[Not Found]Location[-] Reason[notFound] Domain[global]]]

奇怪的是,在https://www.googleapis.com/calendar/v3/users/me/calendarList?alt=json&prettyPrint=true 执行 GET 不会返回 something,所以它应该在那里。

我希望那里有一些很棒的男孩/女孩知道该做什么!我完全被困住了。

更新 好像我在 CalendarList Google Api Explorer 上也收到了同样的 404 错误:

网址https://developers.google.com/google-apps/calendar/v3/reference/calendarList/insert

请求

POST https://www.googleapis.com/calendar/v3/users/me/calendarList?key={YOUR_API_KEY}

Content-Type:  application/json
Authorization:  Bearer ya29.AHES6ZQTj-D6uIMOWr_AoFYVvfefsEGcVvLvvMf4aKhgrdvQE25aVw
X-JavaScript-User-Agent:  Google APIs Explorer

{
 "id": "hastalavista"
}

回应

404 Not Found

- Show headers -    {  "error": {   "errors": [    {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"    }   ],   "code": 404,   "message": "Not Found"  } }

有谁知道 Google 是否更改了此资源的 URL?如果是,我如何更改 Google Calendar Api v3 以使用更新后的 url ...?

【问题讨论】:

    标签: http-status-code-404 google-calendar-api gdata


    【解决方案1】:

    好吧,我的错:

    您不能使用自己的标识符创建日历,CalendarListEntry.Insert() 的目的是将创建的日历插入日历列表中

    因此,要创建新日历,您必须:

    1. 插入新日历:https://developers.google.com/google-apps/calendar/v3/reference/calendars/insert

      (不要添加id作为参数,这会自动创建)

    2. 将步骤1中创建的日历的ID插入到calendarList中:https://developers.google.com/google-apps/calendar/v3/reference/calendarList/insert

    【讨论】:

      【解决方案2】:

      我仍然对 Google 对 Calendar 和 CalendarList 的区别感到完全困惑,因为数据似乎重叠。为什么日历被视为“次要”日历。

      【讨论】:

        【解决方案3】:

        下一个代码对我来说是个窍门,提到的参考是 Java 而不是 .Net,并且像往常一样存在一些令人讨厌的差异......

        私有 bool createCalendar() {

                // use Google.Apis.Calendar
                Calendar calendar = new Calendar();
                calendar.Summary = "MyNewCalendar";
                calendar.Description = "Your new Calendar";
                calendar.Location = "Aadorp";
                calendar.TimeZone = "Europe/Amsterdam";
        
                try
                {
                    // Not inserting in CalendarList but in Calendar!
                    calendarService.Calendars.Insert(calendar).Execute();
                }
                catch (Exception exception)
                {
        
                    MessageBox.Show(exception.Message);
                    return false;
                }
                return true;
            }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-10-30
          • 2019-03-27
          • 1970-01-01
          • 2016-12-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多