使用c#.net与Google Calendar Api v3创建日历时出现错误404
我正在尝试使用Google Calendar API v3创建日历(如果尚不存在).我的实现成功地检索了我的所有日历和事件,并且可以更改日历,但是我在添加新日历方面很费力.我这样做是为了尝试为用户添加新日历:
I am trying to create a calendar using Google Calendar API v3 if it does not already exist. My implementation successfully retrieves all my calendars and events and can change calendars, but I am struggling with adding a new calendar. This is what I do in order to try to add a new calendar for the user:
...
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 不会返回某物,因此它应该在那里.
Weird thing is that doing a GET at https://www.googleapis.com/calendar/v3/users/me/calendarList?alt=json&prettyPrint=true does not return something, so it should be there.
我希望那里有一些很棒的男孩/女孩知道该怎么做!我完全被困住了.
I hope that there is some awesome guy/girl out there which knows what to do! I'm completely stuck.
更新 似乎我也在CalendarList Google Api Explorer上收到相同的404错误:
Update Seems like I am receiving the same 404 error on CalendarList Google Api Explorer also:
网址: 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 ...?
Does anyone know whether Google have changed the URL for this resource? And if yes, how I change the Google Calendar Api v3 to use the updated url ...?
Okey,我不好:
您无法使用自己的标识符创建日历,CalendarListEntry.Insert()的目的是将创建的日历插入日历列表中
You can't create a calendar with your own identifier, the purpose of CalendarListEntry.Insert() is to insert a created Calendar into the list of calendars
因此要创建新的日历,必须执行以下操作:
(请勿将id添加为参数,这会自动创建)
(DO NOT add id as paramater, this will be automatically created)
插入步骤1中创建的日历的ID,并将其插入calendarList: https://developers.google.com/google-apps/calendar/v3/reference/calendarList/insert
Insert the ID of the calendar created in step 1 and insert it into the calendarList: https://developers.google.com/google-apps/calendar/v3/reference/calendarList/insert