繁体   English   中英

C#Google日历

[英]C# Google Calendar

一切都已经在Google日历api上设置好了(不确定我是否配置正确或错过了什么),我创建了一个ac#控制台应用程序,该应用程序将约会写入了Google日历。

我想要实现的是,我希望获得所有订阅我的应用程序的用户或订户,因此,如果发生事件,我可以在日历上写些什么。

我需要什么配置?

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

需要考虑的一些问题:

  1. 这是什么日历? 一个公开的?
  2. 他们如何在您的控制台上订阅?
  3. 当软件关闭,崩溃等情况下会发生什么?
  4. 将事件写入日历 ,您是否需要知道该事件?
  5. 如果不是,新订户是否会获得以前添加的日历条目?

除此之外,您还应该看看Webclient 然后,我们这里有Google Calendar API的参考。 您要搜索的主要请求方法是: Events Insert 这样,我们就可以制作自己的inseration变体。

```

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM