2

我想从google-api-go-client将时间表设置为 google 日历。

我厌倦了用谷歌日历应用程序设置时间表:(

有样品吗?

4

1 回答 1

1

您可以使用谷歌日历 API 的快速入门。详细信息是https://developers.google.com/google-apps/calendar/quickstart/go

而当你想创建事件时,你可以使用“事件:插入”。您可以在此处查看详细信息。

看来你住在日本。因此,当您使用示例脚本时,请注意DateTimeTimeZone

如果您使用以上两个示例,main()则变为如下。在运行示例脚本之前,请确认是否在 Google API 控制台中启用了 Google Calendar API。DateTime并且TimeZone是给日本的。有关详细信息,请查看上述文档站点。

脚本 :

func main() {
    ctx := context.Background()
    b, err := ioutil.ReadFile("client_secret.json")
    if err != nil {
        log.Fatalf("Unable to read client secret file: %v", err)
    }
    // If modifying these scopes, delete your previously saved credentials
    // at ~/.credentials/calendar-go-quickstart.json
    config, err := google.ConfigFromJSON(b, calendar.CalendarScope)
    if err != nil {
        log.Fatalf("Unable to parse client secret file to config: %v", err)
    }
    client := getClient(ctx, config)
    srv, err := calendar.New(client)
    if err != nil {
        log.Fatalf("Unable to retrieve calendar Client %v", err)
    }

    event := &calendar.Event{
        Summary:     "Sample event",
        Location:    "Sample location",
        Description: "This is a sample event.",
        Start: &calendar.EventDateTime{
            DateTime: "2017-04-22T00:00:00+09:00",
            TimeZone: "Asia/Tokyo",
        },
        End: &calendar.EventDateTime{
            DateTime: "2017-04-22T01:00:00+09:00",
            TimeZone: "Asia/Tokyo",
        },
    }
    calendarID := "#####"
    event, err = srv.Events.Insert(calendarID, event).Do()
    if err != nil {
        log.Fatalf("Unable to create event. %v\n", err)
    }
    fmt.Printf("Event created: %s\n", event.HtmlLink)
}
于 2017-04-21T06:18:27.367 回答