获取事件
命名空间:microsoft.graph
获取指定的 event 对象的属性和关系。
目前,此操作返回纯 HTML 格式的事件正文。
在下列两种情况下,应用程序可获取其他用户的日历中的事件:
由于 event 资源支持 扩展,因此也可使用 GET 操作获取 事件 实例中的自定义属性和扩展数据。
支持不同时区
对于返回事件的所有 GET 操作,你可以使用 Prefer: outlook.timezone 标头在响应中指定事件开始和结束时间的时区。
例如,下面的 Prefer: outlook.timezone 标头将响应中的开始和结束时间设置为东部标准时间。
Prefer: outlook.timezone="Eastern Standard Time"
如果该事件是在不同的时区中创建的,则根据 Prefer 标头中指定的时区调整开始和结束时间。请查看此 列表 了解支持的时区名称。如果未指定 Prefer: outlook.timezone 标头,则返回用 UTC 表示的开始和结束时间。
可以使用 事件 资源中的 OriginalStartTimeZone 和 OriginalEndTimeZone 属性来查找创建事件时使用的时区。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 | 权限(从最低特权到最高特权) |
|---|---|
| 委派(工作或学校帐户) | Calendars.Read |
| 委派(个人 Microsoft 帐户) | Calendars.Read |
| 应用程序 | Calendars.Read |
HTTP 请求
GET /me/events/{id}
GET /users/{id | userPrincipalName}/events/{id}
GET /groups/{id}/events/{id}
GET /me/calendar/events/{id}
GET /users/{id | userPrincipalName}/calendar/events/{id}
GET /groups/{id}/calendar/events/{id}
GET /me/calendars/{id}/events/{id}
GET /users/{id | userPrincipalName}/calendars/{id}/events/{id}
GET /me/calendargroups/{id}/calendars/{id}/events/{id}
GET /users/{id | userPrincipalName}/calendargroups/{id}/calendars/{id}/events/{id}
可选的查询参数
此方法支持 OData 查询参数 来帮助自定义响应。
请求标头
| 名称 | 类型 | 说明 |
|---|---|---|
| Authorization | string | Bearer {token}。必需。 |
| Prefer: outlook.timezone | string | 用于指定响应中开始时间和结束时间的时区。如果未指定,返回的这些时间值采用 UTC 时区。可选。 |
| Prefer: outlook.body-content-type | string | 要返回的 body 属性的格式。 可取值为“text”或“html”。 如果指定此 Preference-Applied 头,返回 Prefer 头作为证明。 如果未指定此头,采用 HTML 格式返回 body 属性。 可选。 |
请求正文
请勿提供此方法的请求正文。
响应
如果成功,此方法在响应正文中返回 200 OK 响应代码和 event 对象。
示例
请求 1
第一个示例获取指定的事件。它指定以下内容:
- 获取以太平洋标准时间格式返回的日期时间值的
Prefer: outlook.timezone标头。 - 返回特定属性的
$select查询参数。如果没有$select参数,将返回所有事件属性。
GET https://graph.microsoft.com/v1.0/me/events/AAMkAGIAAAoZDOFAAA=?$select=subject,body,bodyPreview,organizer,attendees,start,end,location,hideAttendees
Prefer: outlook.timezone="Pacific Standard Time"
响应 1
下面是一个响应示例。以 HTML 默认格式返回 body 属性。
HTTP/1.1 200 OK
Content-type: application/json
Preference-Applied: outlook.timezone="Pacific Standard Time"
{
"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('cd209b0b-3f83-4c35-82d2-d88a61820480')/events(subject,body,bodyPreview,organizer,attendees,start,end,location,hideAttendees)/$entity",
"@odata.etag":"W/\"ZlnW4RIAV06KYYwlrfNZvQAAKGWwbw==\"",
"id":"AAMkAGIAAAoZDOFAAA=",
"subject":"Orientation ",
"bodyPreview":"Dana, this is the time you selected for our orientation. Please bring the notes I sent you.",
"body":{
"contentType":"html",
"content":"<html><head></head><body><p>Dana, this is the time you selected for our orientation. Please bring the notes I sent you.</p></body></html>"
},
"start":{
"dateTime":"2017-04-21T10:00:00.0000000",
"timeZone":"Pacific Standard Time"
},
"end":{
"dateTime":"2017-04-21T12:00:00.0000000",
"timeZone":"Pacific Standard Time"
},
"location": {
"displayName": "Assembly Hall",
"locationType": "default",
"uniqueId": "Assembly Hall",
"uniqueIdType": "private"
},
"locations": [
{
"displayName": "Assembly Hall",
"locationType": "default",
"uniqueIdType": "unknown"
}
],
"attendees":[
{
"type":"required",
"status":{
"response":"none",
"time":"0001-01-01T00:00:00Z"
},
"emailAddress":{
"name":"Samantha Booth",
"address":"samanthab@a830edad905084922E17020313.onmicrosoft.com"
}
},
{
"type":"required",
"status":{
"response":"tentativelyAccepted",
"time":"0001-01-01T00:00:00Z"
},
"proposedNewTime": {
"start": {
"dateTime": "2019-08-16T12:00:00.0000000",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2019-08-16T14:00:00.0000000",
"timeZone": "Pacific Standard Time"
}
},
"emailAddress":{
"name":"Dana Swope",
"address":"danas@a830edad905084922E17020313.onmicrosoft.com"
}
}
],
"hideAttendees": false,
"organizer":{
"emailAddress":{
"name":"Samantha Booth",
"address":"samanthab@a830edad905084922E17020313.onmicrosoft.com"
}
}
}
请求 2
第二个示例显示获取指定多个地点的事件。 该请求指定返回特定属性的 $select 查询参数。
GET https://graph.microsoft.com/v1.0/me/events/AAMkADAGAADDdm4NAAA=?$select=subject,body,bodyPreview,organizer,attendees,start,end,location,locations
响应 2
下面是响应的示例。位置 属性包含为其组织事件的 3 个位置的详细信息。
由于该请求未指定任何 Prefer: outlook.timezone 标头,start 和 end 属性将以默认的 UTC 时区显示。
事件正文采用的是默认的 HTML 格式。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('d1a2fae9-db66-4cc9-8133-2184c77af1b8')/events(subject,body,bodyPreview,organizer,attendees,start,end,location,locations)/$entity",
"@odata.etag":"W/\"y53lbKh6jkaxHzFwGhgyxgAAw5zhug==\"",
"id":"AAMkADAGAADDdm4NAAA=",
"subject":"Plan summer company picnic",
"bodyPreview":"Let's kick-start this event planning!",
"body":{
"contentType":"html",
"content":"<html>\r\n<head>\r\n</head>\r\n<body>\r\nLet's kick-start this event planning!\r\n</body>\r\n</html>\r\n"
},
"start":{
"dateTime":"2017-08-30T11:00:00.0000000",
"timeZone":"UTC"
},
"end":{
"dateTime":"2017-08-30T12:00:00.0000000",
"timeZone":"UTC"
},
"location":{
"displayName":"Conf Room 3; Fourth Coffee; Home Office",
"locationType":"default",
"uniqueId":"Conf Room 3; Fourth Coffee; Home Office",
"uniqueIdType":"private"
},
"locations":[
{
"displayName":"Conf Room 3",
"locationType":"default",
"uniqueIdType":"unknown"
},
{
"displayName":"Fourth Coffee",
"locationType":"default",
"uniqueId":"Fourth Coffee",
"uniqueIdType":"private",
"address":{
"street":"4567 Main St",
"city":"Redmond",
"state":"WA",
"countryOrRegion":"US",
"postalCode":"32008"
},
"coordinates":{
"latitude":47.672,
"longitude":-102.103
}
},
{
"displayName":"Home Office",
"locationType":"default",
"uniqueIdType":"unknown"
}
],
"attendees":[
{
"type":"required",
"status":{
"response":"none",
"time":"0001-01-01T00:00:00Z"
},
"emailAddress":{
"name":"Dana Swope",
"address":"DanaS@contoso.onmicrosoft.com"
}
},
{
"type":"required",
"status":{
"response":"none",
"time":"0001-01-01T00:00:00Z"
},
"emailAddress":{
"name":"Alex Wilber",
"address":"AlexW@contoso.onmicrosoft.com"
}
}
],
"organizer":{
"emailAddress":{
"name":"Adele Vance",
"address":"AdeleV@contoso.onmicrosoft.com"
}
}
}
另请参阅
反馈
提交和查看相关反馈