2016-08-12 97 views
1

如何使用ASP.NET C#在我的網站中添加更新和刪除事件到我的Google日曆?使用ASP.NET刪除和更新Google事件[Google日曆]

+0

您正在尋找Google Calendar API。 – SLaks

+0

不,我正在搜索如何從我的網站上操作我的活動(刪除,更新) –

+0

請看看這裏:https://developers.google.com/google-apps/calendar/quickstart/dotnet – Kadaj

回答

0

您可以使用方法Calendars: update更新日曆的元數據。和Calendars: delete刪除輔助日曆。使用Calendars.clear清除主日曆上的所有事件。

樣品HTTP請求:

更新:PUT https://www.googleapis.com/calendar/v3/calendars/calendarId
刪除:DELETE https://www.googleapis.com/calendar/v3/calendars/calendarId
清除:POST https://www.googleapis.com/calendar/v3/calendars/calendarId/clear

發現這個thread與谷歌日曆API V3工作.NET代碼。

更新事件:

public string CreateUpdateEvent(string ExpKey, string ExpVal, string evTitle, string evDate) 
    { 
     EventsResource er = new EventsResource(calService); 
     var queryEvent = er.List(calID); 
     queryEvent.SharedExtendedProperty = ExpKey + "=" + ExpVal; //"EventKey=9999" 
     var EventsList = queryEvent.Execute(); 

     Event ev = new Event(); 
     EventDateTime StartDate = new EventDateTime(); 
     StartDate.Date = evDate; //"2014-11-17"; 
     EventDateTime EndDate = new EventDateTime(); 
     EndDate.Date = evDate; 

     ev.Start = StartDate; 
     ev.End = EndDate; 
     ev.Summary = evTitle; //"My Google Calendar V3 Event!"; 

     string FoundEventID = String.Empty; 
     foreach(var evItem in EventsList.Items) 
     { 
      FoundEventID = evItem.Id; 
     } 

     if (String.IsNullOrEmpty(FoundEventID)) 
     { 
      //If event does not exist, Append Extended Property and create the event 
      Event.ExtendedPropertiesData exp = new Event.ExtendedPropertiesData(); 
      exp.Shared = new Dictionary<string, string>(); 
      exp.Shared.Add(ExpKey, ExpVal); 
      ev.ExtendedProperties = exp; 
      return er.Insert(ev, calID).Execute().Summary; 
     } 
     else 
     { 
      //If existing, Update the event 
      return er.Update(ev, calID, FoundEventID).Execute().Summary; 
     } 
    } 

刪除事件:

public bool DeleteEvent(string ExpKey, string ExpVal) 
    { 
     EventsResource er = new EventsResource(calService); 
     var queryEvent = er.List(calID); 

     queryEvent.SharedExtendedProperty = ExpKey + "=" + ExpVal; //"EventKey=9999" 
     var EventsList = queryEvent.Execute(); 

     string FoundEventID = String.Empty; 
     foreach (Event ev in EventsList.Items) 
     { 
      FoundEventID = ev.Id; 
      er.Delete(calID, FoundEventID).Execute(); 
      return true; 
     } 

     return false; 
    } 

檢查也是這個Quickstart tutorial from Google documentation

+0

這就是我搜索,謝謝:) –

+0

什麼是「calService」? –

相關問題