英文:
Add reminder on google calendar with golang
问题
我想使用golang向Google日历添加自定义提醒:
event := &calendar.Event{
Summary: "Test GG calendar",
Location: "31 AAA",
Description: "Test google calendar",
Start: &calendar.EventDateTime{
DateTime: "2016-12-27T17:30:00+07:00",
TimeZone: "Asia/Ho_Chi_Minh",
},
End: &calendar.EventDateTime{
DateTime: "2016-12-27T17:40:00+07:00",
TimeZone: "Asia/Ho_Chi_Minh",
},
Reminders: &calendar.EventReminders{
Overrides: []*calendar.EventReminder{
{Method: "email", Minutes: 30},
{Method: "popup", Minutes: 10},
},
UseDefault: false,
},
}
当我运行这段代码时,Google无法添加事件。我收到了以下错误信息:无法创建事件。googleapi: Error 400: Cannot specify both default reminders and overrides at the same time., cannotUseDefaultRemindersAndSpecifyOverride
谢谢。
英文:
I want to add a custom reminder to Google Calendar with golang:
event := &calendar.Event{
Summary: "Test GG calendar",
Location: "31 AAA",
Description: "Test google calendar",
Start: &calendar.EventDateTime{
DateTime: "2016-12-27T17:30:00+07:00",
TimeZone: "Asia/Ho_Chi_Minh",
},
End: &calendar.EventDateTime{
DateTime: "2016-12-27T17:40:00+07:00",
TimeZone: "Asia/Ho_Chi_Minh",
},
Reminders: &calendar.EventReminders{
Overrides: []*calendar.EventReminder{
{Method: "email", Minutes: 30},
{Method: "popup", Minutes: 10},
},
UseDefault: false,
},
}
When I run this code, google could not add event. I received this error: Unable to create event. googleapi: Error 400: Cannot specify both default reminders and overrides at the same time., cannotUseDefaultRemindersAndSpecifyOverride
Thanks
答案1
得分: 2
根据我对google-apps/calendar/concepts/reminders的阅读,似乎在设置Overrides
时不应同时指定UseDefault: false
。不要包含UseDefault: false
部分,它将默认为false,只有在想要删除已经存在的覆盖时才需要设置。
所以预期的代码是:
event := &calendar.Event{
Summary: "测试GG日历",
Location: "31 AAA",
Description: "测试谷歌日历",
Start: &calendar.EventDateTime{
DateTime: "2016-12-27T17:30:00+07:00",
TimeZone: "Asia/Ho_Chi_Minh",
},
End: &calendar.EventDateTime{
DateTime: "2016-12-27T17:40:00+07:00",
TimeZone: "Asia/Ho_Chi_Minh",
},
Reminders: &calendar.EventReminders{
Overrides: []*calendar.EventReminder{
{Method: "email", Minutes: 30},
{Method: "popup", Minutes: 10},
},
},
}
英文:
Based on my reading of google-apps/calendar/concepts/reminders, it seems that you should not specify the UseDefault: false,
at the same time as setting the Overrides
. Do not put the UseDefault: false,
part, and it will be defaulting to false as its only required to set when wanting to remove overrides that are in place already.
So the expected code is:
event := &calendar.Event{
Summary: "Test GG calendar",
Location: "31 AAA",
Description: "Test google calendar",
Start: &calendar.EventDateTime{
DateTime: "2016-12-27T17:30:00+07:00",
TimeZone: "Asia/Ho_Chi_Minh",
},
End: &calendar.EventDateTime{
DateTime: "2016-12-27T17:40:00+07:00",
TimeZone: "Asia/Ho_Chi_Minh",
},
Reminders: &calendar.EventReminders{
Overrides: []*calendar.EventReminder{
{Method: "email", Minutes: 30},
{Method: "popup", Minutes: 10},
},
},
}
答案2
得分: 0
你应该使用ForceSendFields
和UseDefault
,并将UseDefault
设置为false
。
&calendar.EventReminders{
Overrides: []*calendar.EventReminder{
{
Method: "email",
Minutes: 12,
},
},
UseDefault: false,
ForceSendFields: []string{"UseDefault"},
}
英文:
You should send ForceSendFields
with UseDefault
and set UseDefault
to false
&calendar.EventReminders{
Overrides: []*calendar.EventReminder{
{
Method: "email",
Minutes: 12,
},
},
UseDefault: false,
ForceSendFields: []string{"UseDefault"},
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论