我正在尝试使用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 ...?
哦,我的坏:
您无法使用自己的标识符创建日历,CalendarListEntry.Insert()的目的是将创建的日历插入日历列表中
因此,要创建新日历,必须:
由于数据似乎重叠,我仍然对Google在Calendar和CalendarList之间的区别感到困惑。为什么日历被视为“次要”日历。
下一个代码为我提供了诀窍,上面提到的参考文献是Java而不是.Net,和往常一样,是一些令人讨厌的差异......
private bool createCalendar(){
https://developers.google.com/google-apps/calendar/v3/reference/calendarList/insert