C#谷歌日历

本文关键字:日历 谷歌 | 更新日期: 2023-09-27 17:59:20

一切都已经在谷歌日历api上设置好了(不确定我是正确配置还是遗漏了什么)我创建了一个c#控制台应用程序,它将约会写入谷歌日历。

我想实现的是,我想让所有订阅我的应用程序的用户或订阅者,这样我就可以写什么了如果有活动,在日历上。

我需要什么配置?

C#谷歌日历

这实际上是一个多域问题。

需要考虑的一些问题:

  1. 它是什么日历?公开的
  2. 他们如何订阅您的控制台
  3. 当软件关闭、崩溃等时会发生什么
  4. 您需要知道写入日历后的事件
  5. 如果没有,新用户是否会获得以前添加的日历条目

除此之外,您还应该了解一下Webclient。然后我们在这里有参考谷歌日历API。您正在搜索的主要请求方法是:事件插入。有了这个,我们就可以制作自己的受精变体。

```

private readonly List<string> _calendarIDs;
/* lets assume you imported webrequests and you're going to write a method
 * Further we assume, you have a List of calendars as object attribute
 */
public void InsertEntry(DateTime start, DateTime end,
   string title, string description) {
    using(var client = new WebClient()) {
        var epochTicks = new DateTime(1970, 1, 1);
        var values = new NameValueCollection();
        values["attachements[].fileUrl"] = "";
        values["attendees[].email"] = "";
        values["end.date"] = end.ToString("yyyy-MM-dd");
        values["end.dateTime"] = (end - epoch).Seconds;
        values["reminders.overrides[].minutes"] = 0;
        values["start.date"] = start.ToString("yyyy-MM-dd");
        values["start.dateTime"] = (start - epoch).Seconds;
        values["summary"] = title; // This is the calendar entrys title
        values["description"] = description;
        foreach(string calendarID in _calendarIDs) {
            var endpoint = String.Format("https://www.googleapis.com/calendar/v3/calendars/{0}/events", calendarID)
            var response = client.UploadValues(endpoint, values);
            var responseString = Encoding.Default.GetString(response);
    }
}

这是一个最小的例子,api有很多端点和参数。你应该深入研究一下,也许你会发现更有用的参数。

下面是示例代码,

GoogleCalendarUtils utils = new GoogleCalendarUtils();
ArrayList months = /* the list of months*/;
//    Update the content window.
foreach( ThistleEventMonth month in months )
{
    foreach( ThistleEvent thistleEvent in month.ThistleEvents )
    {
        utils.InsertEntry( thistleEvent );
    }
}