Google Calendar API,只需知道某人的电子邮件地址就可以将事件添加到某人的日历中 [英] Google Calendar API, Adding an event to someones calendar just by knowing their e-mail address

查看:41
本文介绍了Google Calendar API,只需知道某人的电子邮件地址就可以将事件添加到某人的日历中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have downloaded the Google.Apis namespace:

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

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

I've spent the entire day looking on the web to see .NET samples about how I can possible add an event to someones calendar just by knowing their e-mail address.

我尝试了以下代码,但它出现了错误,而且很明显它不起作用:

I tried the following code, but it's bringing up errors and it's quite obvious that it isn't going to work:

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"

}

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

Any help is appreciated! Even samples of other code :)

推荐答案

创建事件并插入事件的部分存在语法错误.下面是一个对 Google API .NET 库有正确语法的片段:

There are syntax errors in the part where you create the event and insert it. Here is a snippet that has correct syntax for the Google API .NET library:

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();

这篇关于Google Calendar API,只需知道某人的电子邮件地址就可以将事件添加到某人的日历中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆