使用OAuth,我确实从Google获得了访问令牌。谷歌甚至这个示例附带的示例:
http://code.google.com/p/google-api-dotnet-client/source/browse/Tasks.SimpleOAuth2/Program.cs?repo=samples
演示如何使用任务 API。但是,我想使用日历 API。我想访问用户的日历。谁能告诉我该怎么做?
看看样本:
.NET 客户端库
入门在上面链接的页面右侧,有一个屏幕截图,显示了 Google 数据 API 解决方案中包含的示例项目。事实证明它们非常有用(我用它们来启动我自己的Google日历应用程序)。
我建议同时打开自己的解决方案和示例解决方案。这样,您可以在示例和您自己的实现之间切换。
我还建议使用 NuGet 包:
- Google.GData.AccessControl
- Google.GData.Calendar
- Google.GData.Client
- Google.GData.Extensions
- 以及更多...
这样,您可以轻松地保持最新状态。
获取用户日历的示例:
public void LoadCalendars()
{
// Prepare service
CalendarService service = new CalendarService("Your app name");
service.setUserCredentials("username", "password");
CalendarQuery query = new CalendarQuery();
query.Uri = new Uri("https://www.google.com/calendar/feeds/default/allcalendars/full");
CalendarFeed calendarFeed = (CalendarFeed)service.Query(query);
Console.WriteLine("Your calendars:n");
foreach(CalendarEntry entry in calendarFeed.Entries)
{
Console.WriteLine(entry.Title.Text + "n");
}
}