事件创建由函数实现:
func CreateEvent(startDate time.Time, duration int, headerText string) (string, error) {
endDate := startDate.Add(time.Hour * time.Duration(duration))
event := &calendar.Event{
Summary: headerText,
Description: "AutomateCreate",
Start: &calendar.EventDateTime{
DateTime: startDate.Format(time.RFC3339),
TimeZone: "Europe/Moscow",
},
End: &calendar.EventDateTime{
DateTime: endDate.Format(time.RFC3339),
TimeZone: "Europe/Moscow",
},
ConferenceData: &calendar.ConferenceData{
CreateRequest: &calendar.CreateConferenceRequest{
ConferenceSolutionKey: &calendar.ConferenceSolutionKey{
Type: "hangoutsMeet",
},
RequestId: uuid.New().String(),
},
},
}
event, err := calendarService.Events.Insert("[email protected]", event).ConferenceDataVersion(1).Do()
if err != nil {
return "", err
}
text := event.Summary + "\n" + event.HangoutLink
return text, nil
}
我收到错误:
googleapi: Error 400: Invalid conference type value., invalid
此外,无需见面即可创建活动/
我正在使用库链接日历/v3
这是您的代码以及服务帐户模拟。
这对我有用:事件是通过环聊创建的,并返回环聊 URL。
package main
import (
"context"
"log/slog"
"os"
"time"
"github.com/google/uuid"
"golang.org/x/oauth2/google"
"google.golang.org/api/calendar/v3"
"google.golang.org/api/option"
)
func main() {
scopes := []string{
calendar.CalendarScope,
}
key := os.Getenv("KEY")
b, err := os.ReadFile(key)
if err != nil {
panic(err)
}
config, err := google.JWTConfigFromJSON(b, scopes...)
if err != nil {
panic(err)
}
subject := os.Getenv("EMAIL")
config.Subject = subject
ctx := context.Background()
client := config.Client(ctx)
opts := []option.ClientOption{
option.WithHTTPClient(client),
}
calendarService, err := calendar.NewService(ctx, opts...)
if err != nil {
panic(err)
}
startDate := time.Now()
duration := 60
endDate := startDate.Add(time.Minute * time.Duration(duration))
headerText := "Stackoverflow: 79290245"
event := &calendar.Event{
Summary: headerText,
Description: "AutomateCreate",
Start: &calendar.EventDateTime{
DateTime: startDate.Format(time.RFC3339),
TimeZone: "US/Pacific",
},
End: &calendar.EventDateTime{
DateTime: endDate.Format(time.RFC3339),
TimeZone: "US/Pacific",
},
ConferenceData: &calendar.ConferenceData{
CreateRequest: &calendar.CreateConferenceRequest{
ConferenceSolutionKey: &calendar.ConferenceSolutionKey{
Type: "hangoutsMeet",
},
RequestId: uuid.New().String(),
},
},
}
resp, err := calendarService.Events.Insert(subject, event).ConferenceDataVersion(1).Do()
if err != nil {
panic(err)
}
slog.Info("Result",
"summary", resp.Summary,
"hangoutLink", resp.HangoutLink)
}