使用Golang在Google日历上添加提醒。

huangapple go评论142阅读模式
英文:

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

你应该使用ForceSendFieldsUseDefault,并将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"},
}

huangapple
  • 本文由 发表于 2016年12月27日 19:11:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/41344074.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定