2

I wanna set the schedule to google calendar from google-api-go-client.

I got tired set the schedule with google calendar application :(

Is there any sample?

Grokify
  • 15,092
  • 6
  • 60
  • 81
Junya Kono
  • 1,121
  • 3
  • 10
  • 16

1 Answers1

1

You can use quicksstart for Google Calendar API. The detail information is https://developers.google.com/google-apps/calendar/quickstart/go.

And when you want to create events, you can use "Events: insert". You can see the detail here.

It seems that you live in Japan. So when you use sample script, please be careful for DateTime and TimeZone.

If you use above both samples, main() becomes as follows. Before run sample script, please confirm whether Google Calendar API is enabled at Google API console. DateTime and TimeZone are for Japan. Please check above document sites about the detail.

Script :

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)
}
Tanaike
  • 181,128
  • 11
  • 97
  • 165