【发布时间】:2016-07-29 08:01:24
【问题描述】:
一切都已经在谷歌日历 api 上设置好了(不确定我是否正确配置或者我错过了一些东西) 我创建了一个 c# 控制台应用程序,它将约会写入谷歌日历。
我想要实现的是,我想获得所有订阅我的应用程序的用户或订阅者,所以我可以写什么 如果有活动,在日历上。
我需要什么配置?
【问题讨论】:
标签: c# google-calendar-api windows-console
一切都已经在谷歌日历 api 上设置好了(不确定我是否正确配置或者我错过了一些东西) 我创建了一个 c# 控制台应用程序,它将约会写入谷歌日历。
我想要实现的是,我想获得所有订阅我的应用程序的用户或订阅者,所以我可以写什么 如果有活动,在日历上。
我需要什么配置?
【问题讨论】:
标签: c# google-calendar-api windows-console
这实际上是一个多域问题。
需要考虑的一些问题:
除此之外,您应该看看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 有很多端点和参数。你应该深入研究一下,也许你会发现更有用的参数。
【讨论】:
下面是示例代码,
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 );
}
}
【讨论】: