使用C#和Microsoft Graph SDK从日历获取事件 [英] Getting Events from Calendar using C# and Microsoft Graph SDK

查看:222
本文介绍了使用C#和Microsoft Graph SDK从日历获取事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个控制台应用程序,以列出,删除事件并将事件添加到特定用户的日历中.我正在开发业务流程.我首先列出事件.

I'm trying to develop a console app to list, remove and add events to a specific user's calendar. I'm developing a business process. I'm starting by listing events.

Calendar cal =
    client
    .Users["UserName@CompanyName.com"]
    .Calendars["AAMkAGIzZDM4O...."]
    .Request()
    .GetAsync()
    .Result;

我获得了正确的日历,但是事件"集合为空.日历中有13个事件.我具有日历读/写权限.

I get the correct calendar back but the Events collection is null. There are 13 events in the calendar. I have Calendar Read/Write permissions.

有什么想法吗?

推荐答案

我没有测试c#Graph SDK的环境,但是我怀疑基础查询不会向Graph询问日历事件,所以这就是为什么字段为空.

I don't have an environment to test the c# Graph SDK, but I suspect the underlying query doesn't ask Graph for the calendar events so that's why the field is null.

使用图形浏览器( https://developer.microsoft.com/zh-cn/graph/graph-explorer#),我们可以尝试进行等效查询,并注意仅返回有关日历的元数据.

Using Graph explorer (https://developer.microsoft.com/en-us/graph/graph-explorer#), we can try an equivalent query and note only metadata about the calendars are returned.

GET https://graph.microsoft.com/v1.0/me/calendars

图形浏览器有一些日历示例查询.默认情况下,它们可能不可见,因此请单击显示更多样本"链接.

The Graph explorer has some calendar sample queries. They might not be visible by default, so click the 'show more samples' link.

all events in my calendar示例查询可能正是您要查找的.该请求是:

The all events in my calendar sample query is probably what you're looking for. The request is:

GET https://graph.microsoft.com/v1.0/me/events?$select=subject,body,bodyPreview,organizer,attendees,start,end,location

(如果需要特定日历的事件,则为/calendars/{calendar-id}/events)

(or /calendars/{calendar-id}/events if you want events for a specific calendar)

下一步是将该REST API查询转换为SDK语法,以便在您的应用程序中使用.

The next step is converting this REST API query into the SDK syntax to use in your application.

来自除了查询事件外,您可能还希望研究

Besides querying the events, you might also want to look into querying the users calendar view which allows you to specify a start and end date.

这篇关于使用C#和Microsoft Graph SDK从日历获取事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆