2016-07-29 114 views
0

一切都已經安裝在谷歌日曆API(不知道我是否配置正確或我錯過了一些東西) 我創建了一個C#控制檯應用程序,寫約會到谷歌日曆。C#谷歌日曆

我想要實現的是,我想獲得訂閱我應用程序的所有用戶或訂閱者,所以如果有事件發生,我可以在該日曆上寫上 。

我需要什麼配置?

回答

-1

下面是示例代碼,

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

如果訂閱我的應用的用戶,我如何獲得列表? – PongPagong

+0

您必須使用Google OAuth 2.0獲取信息,然後進行處理。 – Thennarasan

+0

我已經應用了oAuth 2.0。問題是我如何獲得訂戶列表 – PongPagong

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有很多的端點和參數。你應該深入研究它,也許你會發現更有用的參數。