gpt4 book ai didi

c# - Google Calendar API,只需知道某人的电子邮件地址即可将事件添加到某人的日历中

转载 作者:太空狗 更新时间:2023-10-29 18:22:11 27 4
gpt4 key购买 nike

我已经下载了 Google.Apis 命名空间:

using Google.Apis.Auth.OAuth2;
using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;
using Google.Apis.Services;

我花了一整天的时间在网上查看 .NET 示例,了解如何仅通过知道他们的电子邮件地址就可以将事件添加到他们的日历中。

我尝试了下面的代码,但它出现了错误,而且很明显它无法正常工作:

Public void Method(string email, string text)
{
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "CLIENTID",
ClientSecret = "CLIENTSECRET",
},
new[] { CalendarService.Scope.Calendar },
"user",
CancellationToken.None).Result;

// Create the service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Calendar API Sample",
});


Event event1 = new Event()
{
Summary = "Something",
Location = "Somewhere",
Start = new EventDateTime() {
DateTime = DateTime.Now,
TimeZone = "America/Los_Angeles"
},
End = new EventDateTime() {
DateTime = DateTime.Now,
TimeZone = "America/Los_Angeles"
},
Attendees = new List<EventAttendee>()
{
new EventAttendee() { Email: email } //bringing up an error "Syntax ',' expected
}
};

Event thisevent = service.Events.Insert(event1, "primary").Fetch(); // Another error. "Does not contain a definition for Fetch"

}

感谢任何帮助!甚至其他代码的示例 :)

最佳答案

您创建和插入事件的部分存在语法错误。以下是 Google API .NET 库的正确语法片段:

Event myEvent = new Event
{
Summary = "Appointment",
Location = "Somewhere",
Start = new EventDateTime() {
DateTime = new DateTime(2014, 6, 2, 10, 0, 0),
TimeZone = "America/Los_Angeles"
},
End = new EventDateTime() {
DateTime = new DateTime(2014, 6, 2, 10, 30, 0),
TimeZone = "America/Los_Angeles"
},
Recurrence = new String[] {
"RRULE:FREQ=WEEKLY;BYDAY=MO"
},
Attendees = new List<EventAttendee>()
{
new EventAttendee() { Email = "johndoe@gmail.com" }
}
};

Event recurringEvent = service.Events.Insert(myEvent, "primary").Execute();

关于c# - Google Calendar API,只需知道某人的电子邮件地址即可将事件添加到某人的日历中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23310152/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com