使用c#.net创建使用Google Calendar Api v3的日历时出错404

问题描述 投票:5回答:3

我正在尝试使用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

RequestError:

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并没有返回什么,所以它应该在那里。

我希望有一些很棒的家伙/女孩知道该怎么做!我完全卡住了。

更新似乎我在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是否更改了此资源的网址?如果是,我如何更改Google Calendar Api v3以使用更新后的URL ...?

http-status-code-404 google-calendar-api gdata
3个回答
11
投票

哦,我的坏:

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

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

  1. 插入一个新日历:qazxsw poi (不要添加id作为参数,这将自动创建)
  2. 插入在步骤1中创建的日历的ID,并将其插入calendarList:https://developers.google.com/google-apps/calendar/v3/reference/calendars/insert

1
投票

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


0
投票

下一个代码为我提供了诀窍,上面提到的参考文献是Java而不是.Net,和往常一样,是一些令人讨厌的差异......

private bool createCalendar(){

https://developers.google.com/google-apps/calendar/v3/reference/calendarList/insert
© www.soinside.com 2019 - 2024. All rights reserved.