【问题标题】:C# Google CalendarC# 谷歌日历
【发布时间】:2016-07-29 08:01:24
【问题描述】:

一切都已经在谷歌日历 api 上设置好了(不确定我是否正确配置或者我错过了一些东西) 我创建了一个 c# 控制台应用程序,它将约会写入谷歌日历。

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

我需要什么配置?

【问题讨论】:

    标签: c# google-calendar-api windows-console


    【解决方案1】:

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

    需要考虑的一些问题:

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

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

    ```

    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 有很多端点和参数。你应该深入研究一下,也许你会发现更有用的参数。

    【讨论】:

      【解决方案2】:

      下面是示例代码,

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

      【讨论】:

      • 如果用户订阅了我的应用,我如何获取列表?
      • 您必须使用 Google OAuth 2.0 获取信息然后进行处理。
      • 我已经应用了 oAuth 2.0。问题是我如何获得订阅者列表
      • 这段代码以什么方式“获取所有订阅我的应用程序的用户或订阅者,所以如果有事件,我可以在日历上写什么。” (不管那是什么意思)?
      • 您不能一次获得所有用户。例如,当用户点击注册事件时,我们调用api获取用户信息并输入到日历中的条目,如果您想保留跟踪记录,您可以保存用户信息用于内部目的。
      猜你喜欢
      • 1970-01-01
      • 2016-04-15
      • 2016-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-12
      • 2015-06-20
      相关资源
      最近更新 更多