使用golang在Google日历上添加提醒

时间:2016-12-27 11:11:15

标签: go google-calendar-api

我想使用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:错误400:无法同时指定默认提醒和覆盖。,couldUseDefaultRemindersAndSpecifyOverride

由于

2 个答案:

答案 0 :(得分:1)

根据我对google-apps/calendar/concepts/reminders的阅读,您似乎不应在设置UseDefault: false,的同时指定Overrides。不要放置UseDefault: false,部分,它将默认为false,因为它只需要在想要删除已经存在的覆盖时设置。

所以预期的代码是:

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},
        },
    },
}

答案 1 :(得分:0)

您应该使用 ForceSendFields 发送 UseDefault 并将 UseDefault 设置为 false

&calendar.EventReminders{
    Overrides: []*calendar.EventReminder{
        {
            Method:  "email",
            Minutes: 12,
        },
    },
    UseDefault:      false,
    ForceSendFields: []string{"UseDefault"},
}