加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Google Calendar API,只需知道他们的电子邮件地址即可向某

发布时间:2020-12-15 08:38:12 所属栏目:百科 来源:网络整理
导读:我已经下载了Google.Apis名称空间: using Google.Apis.Auth.OAuth2;using Google.Apis.Calendar.v3;using Google.Apis.Calendar.v3.Data;using Google.Apis.Services; 我花了一整天的时间在网上查看.NET示例,了解如何通过了解他们的电子邮件地址将事件添加
我已经下载了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,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",Start = new EventDateTime() {
      DateTime = new DateTime(2014,6,2,10,0),TimeZone = "America/Los_Angeles"
  },End = new EventDateTime() {
      DateTime = new DateTime(2014,30,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();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读