获取聊天
命名空间:microsoft.graph
重要
Microsoft Graph /beta
版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
检索一个聊天(不含其消息)。
此方法支持联合。 若要访问聊天,至少一个聊天成员必须属于发起请求的租户。
此 API 可用于以下国家级云部署。
全局服务 | 美国政府 L4 | 美国政府 L5 (DOD) | 由世纪互联运营的中国 |
---|---|---|---|
✅ | ✅ | ✅ | ✅ |
权限
为此 API 选择标记为最低特权的权限。 只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
权限类型 | 最低特权权限 | 更高特权权限 |
---|---|---|
委派(工作或学校帐户) | Chat.ReadBasic | Chat.Read、Chat.ReadWrite |
委派(个人 Microsoft 帐户) | 不支持。 | 不支持。 |
应用程序 | Chat.ReadBasic.WhereInstalled | Chat.Manage.Chat、Chat.Read.All、Chat.ReadBasic.All、Chat.ReadWrite.All、ChatSettings.Read.Chat、ChatSettings.ReadWrite.Chat |
注意
ChatSettings.Read.Chat、ChatSettings.ReadWrite.Chat 和 Chat.Manage.Chat 权限使用 特定于资源的许可。
HTTP 请求
GET /me/chats/{chat-id}
GET /users/{user-id | user-principal-name}/chats/{chat-id}
GET /chats/{chat-id}
可选的查询参数
此操作当前不支持 OData 查询参数 来自定义响应。
请求标头
标头 | 值 |
---|---|
Authorization | 持有者 {token}。 必填。 详细了解 身份验证和授权。 |
请求正文
请勿提供此方法的请求正文。
响应
如果成功,此方法在响应正文中返回 200 OK
响应代码和 chat 对象集合。
示例
示例 1:获取群组聊天
请求
以下示例显示了一个请求。
GET https://graph.microsoft.com/beta/chats/19:b8577894a63548969c5c92bb9c80c5e1@thread.v2
响应
以下示例显示了相应的响应。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#chats/$entity",
"id": "19:b8577894a63548969c5c92bb9c80c5e1@thread.v2",
"topic": "test group 1",
"createdDateTime": "2021-04-06T19:49:52.431Z",
"lastUpdatedDateTime": "2021-04-06T19:54:04.306Z",
"chatType": "group",
"webUrl": "https://teams.microsoft.com/l/chat/19%3Ab8577894a63548969c5c92bb9c80c5e1@thread.v2/0?tenantId=b33cbe9f-8ebe-4f2a-912b-7e2a427f477f",
"tenantId": "b33cbe9f-8ebe-4f2a-912b-7e2a427f477f",
"onlineMeetingInfo": null,
"createdBy": {
"application": null,
"device": null,
"user": {
"@odata.type": "#microsoft.graph.teamworkUserIdentity",
"id": "8c0a1a67-50ce-4114-bb6c-da9c5dbcf6ca",
"displayName": null,
"userIdentityType": "aadUser",
"tenantId": "b33cbe9f-8ebe-4f2a-912b-7e2a427f477f"
}
},
"viewpoint": {
"isHidden": true,
"lastMessageReadDateTime": "2021-05-06T23:55:07.191Z"
},
"isHiddenForAllMembers": false
}
示例 2:通过一次聊天获取用户
请求
以下示例显示了一个请求。
GET https://graph.microsoft.com/beta/users/8b081ef6-4792-4def-b2c9-c363a1bf41d5/chats/19:8b081ef6-4792-4def-b2c9-c363a1bf41d5_877192bd-9183-47d3-a74c-8aa0426716cf@unq.gbl.spaces
响应
以下示例显示了相应的响应。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#chats/$entity",
"id": "19:8b081ef6-4792-4def-b2c9-c363a1bf41d5_877192bd-9183-47d3-a74c-8aa0426716cf@unq.gbl.spaces",
"topic": null,
"createdDateTime": "2019-04-18T23:51:42.099Z",
"lastUpdatedDateTime": "2019-04-18T23:51:43.255Z",
"chatType": "oneOnOne",
"webUrl": "https://teams.microsoft.com/l/chat/19%3A8b081ef6-4792-4def-b2c9-c363a1bf41d5_877192bd-9183-47d3-a74c-8aa0426716cf@unq.gbl.spaces/0?tenantId=2432b57b-0abd-43db-aa7b-16eadd115d34",
"tenantId": "2432b57b-0abd-43db-aa7b-16eadd115d34",
"onlineMeetingInfo": null,
"createdBy": {
"application": null,
"device": null,
"user": {
"@odata.type": "#microsoft.graph.teamworkUserIdentity",
"id": "8c0a1a67-50ce-4114-bb6c-da9c5dbcf6ca",
"displayName": null,
"userIdentityType": "aadUser",
"tenantId": "2432b57b-0abd-43db-aa7b-16eadd115d34"
}
},
"viewpoint": {
"isHidden": false,
"lastMessageReadDateTime": "2021-07-06T22:26:27.98Z"
},
"isHiddenForAllMembers": false
}
示例 3:获取聊天及其所有成员
请求
以下示例显示了一个请求。
GET https://graph.microsoft.com/beta/chats/19:b8577894a63548969c5c92bb9c80c5e1@thread.v2?$expand=members
响应
以下示例显示了相应的响应。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#chats(members())/$entity",
"id": "19:b8577894a63548969c5c92bb9c80c5e1@thread.v2",
"topic": "test group 1",
"createdDateTime": "2021-04-06T19:49:52.431Z",
"lastUpdatedDateTime": "2021-04-21T17:13:44.033Z",
"chatType": "group",
"webUrl": "https://teams.microsoft.com/l/chat/19%3Ab8577894a63548969c5c92bb9c80c5e1@thread.v2/0?tenantId=b33cbe9f-8ebe-4f2a-912b-7e2a427f477f",
"tenantId": "b33cbe9f-8ebe-4f2a-912b-7e2a427f477f",
"onlineMeetingInfo": null,
"createdBy": {
"application": null,
"device": null,
"user": {
"@odata.type": "#microsoft.graph.teamworkUserIdentity",
"id": "8c0a1a67-50ce-4114-bb6c-da9c5dbcf6ca",
"displayName": null,
"userIdentityType": "aadUser",
"tenantId": "b33cbe9f-8ebe-4f2a-912b-7e2a427f477f"
}
},
"viewpoint": {
"isHidden": false,
"lastMessageReadDateTime": "2021-08-09T17:38:24.101Z"
},
"isHiddenForAllMembers": false,
"members": [
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"id": "MCMjMjQzMmI1N2ItMGFiZC00M2RiLWFhN2ItMTZlYWRkMTE1ZDM0IyMxOTpiODU3Nzg5NGE2MzU0ODk2OWM1YzkyYmI5YzgwYzVlMUB0aHJlYWQudjIjIzhjMGExYTY3LTUwY2UtNDExNC1iYjZjLWRhOWM1ZGJjZjZjYQ==",
"roles": [
"owner"
],
"displayName": "John Doe",
"visibleHistoryStartDateTime": "0001-01-01T00:00:00Z",
"userId": "8c0a1a67-50ce-4114-bb6c-da9c5dbcf6ca",
"email": "john@contoso.com",
"tenantId": "b33cbe9f-8ebe-4f2a-912b-7e2a427f477f"
},
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"id": "MCMjMjQzMmI1N2ItMGFiZC00M2RiLWFhN2ItMTZlYWRkMTE1ZDM0IyMxOTpiODU3Nzg5NGE2MzU0ODk2OWM1YzkyYmI5YzgwYzVlMUB0aHJlYWQudjIjIzQ1OTVkMmYyLTdiMzEtNDQ2Yy04NGZkLTliNzk1ZTYzMTE0Yg==",
"roles": [
"owner"
],
"displayName": "Test User 1",
"visibleHistoryStartDateTime": "0001-01-01T00:00:00Z",
"userId": "4595d2f2-7b31-446c-84fd-9b795e63114b",
"email": "testuser1@contoso.com",
"tenantId": "b33cbe9f-8ebe-4f2a-912b-7e2a427f477f"
},
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"id": "MCMjMjQzMmI1N2ItMGFiZC00M2RiLWFhN2ItMTZlYWRkMTE1ZDM0IyMxOTpiODU3Nzg5NGE2MzU0ODk2OWM1YzkyYmI5YzgwYzVlMUB0aHJlYWQudjIjIzgyZmU3NzU4LTViYjMtNGYwZC1hNDNmLWU1NTVmZDM5OWM2Zg==",
"roles": [
"owner"
],
"displayName": "Test User 2",
"visibleHistoryStartDateTime": "0001-01-01T00:00:00Z",
"userId": "82fe7758-5bb3-4f0d-a43f-e555fd399c6f",
"email": "testuser2@contoso.com",
"tenantId": "b33cbe9f-8ebe-4f2a-912b-7e2a427f477f"
},
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"id": "MCMjMjQzMmI1N2ItMGFiZC00M2RiLWFhN2ItMTZlYWRkMTE1ZDM0IyMxOTpiODU3Nzg5NGE2MzU0ODk2OWM1YzkyYmI5YzgwYzVlMUB0aHJlYWQudjIjIzJjOGQyYjVjLTE4NDktNDA2Ni1iNTdkLWU3YTBlOWU0NGVjOA==",
"roles": [
"owner"
],
"displayName": "Test User 3",
"visibleHistoryStartDateTime": "0001-01-01T00:00:00Z",
"userId": "2c8d2b5c-1849-4066-b57d-e7a0e9e44ec8",
"email": "testuser3@contoso.com",
"tenantId": "b33cbe9f-8ebe-4f2a-912b-7e2a427f477f"
},
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"id": "MCMjMjQzMmI1N2ItMGFiZC00M2RiLWFhN2ItMTZlYWRkMTE1ZDM0IyMxOTpiODU3Nzg5NGE2MzU0ODk2OWM1YzkyYmI5YzgwYzVlMUB0aHJlYWQudjIjIzhlYTBlMzhiLWVmYjMtNDc1Ny05MjRhLTVmOTQwNjFjZjhjMg==",
"roles": [
"owner"
],
"displayName": "Test User 4",
"visibleHistoryStartDateTime": "2021-04-20T17:13:43.715Z",
"userId": "8ea0e38b-efb3-4757-924a-5f94061cf8c2",
"email": "testuser4@contoso.com",
"tenantId": "b33cbe9f-8ebe-4f2a-912b-7e2a427f477f"
}
]
}
示例 4:获取与 Microsoft Teams 会议关联的聊天的详细信息
请求
以下示例显示了一个请求。
GET https://graph.microsoft.com/beta/chats/19:meeting_ZDZlYTYxOWUtYzdlMi00ZmMxLWIxMTAtN2YzODZlZjAxYzI4@thread.v2
响应
以下示例显示了相应的响应。
HTTP/1.1 200 OK
Content-type: application/json
{
"id": "19:meeting_YDZlYTYxOWUtYzdlMi00ZmMxLWIxMTAtN2YzODZlZjAxYzI4@thread.v2",
"topic": "Test Meeting",
"createdDateTime": "2021-08-17T12:21:37.322Z",
"lastUpdatedDateTime": "2021-08-18T00:31:31.817Z",
"chatType": "meeting",
"webUrl": "https://teams.microsoft.com/l/chat/19%3Ameeting_YDZlYTYxOWUtYzdlMi00ZmMxLWIxMTAtN2YzODZlZjAxYzI4%40thread.v2/0?tenantId=2432b57b-0abd-43db-aa7b-16eadd115d34",
"tenantId": "2432b57b-0abd-43db-aa7b-16eadd115d35",
"viewpoint": {
"isHidden": false,
"lastMessageReadDateTime": "2021-08-17T18:04:32.583Z"
},
"isHiddenForAllMembers": false,
"onlineMeetingInfo": {
"calendarEventId": "AAMkADAzMjNhY2NiLWVmNDItNDVjYS05MnFjLTExY2U0ZWMyZTNmZQBGAAAAAAARDMODhhR0TZRGWo9nN0NcBwAmvYmLhDvYR6hCFdQLgxR-AAAAAAENAAAmvYmLhDvYR6hCFdQLgxR-AABkrglJAAA=",
"joinWebUrl": "https://teams.microsoft.com/l/meetup-join/19%3Ameeting_YDZlYTYxOWUtYzdlMi00ZmMxLWIxMTAtN2YzODZlZjAxYzI4%40thread.v2/0?context=%7b%22Tid%22%3a%222432b57b-0abd-43db-aa7b-16eadd115d34%22%2c%22Oid%22%3a%22bfb5bb25-3a8d-487d-9828-7875ced51a30%22%7d",
"organizer": {
"id": "bfb5bb25-3a8d-487d-9828-7875ced51a30",
"displayName": null,
"userIdentityType": "aadUser"
}
},
"createdBy": {
"application": null,
"device": null,
"user": {
"@odata.type": "#microsoft.graph.teamworkUserIdentity",
"id": "bfb5bb25-3a8d-487d-9828-7875ced51a30",
"displayName": null,
"userIdentityType": "aadUser",
"tenantId": "2432b57b-0abd-43db-aa7b-16eadd115d34"
}
}
}
示例 5:获取聊天以及聊天中最后发送的消息的预览
请求
以下示例显示了一个请求。
GET https://graph.microsoft.com/beta/chats/19:ebe3857aa388434bab0cad9d2e09f4de@thread.v2?$expand=lastMessagePreview
响应
以下示例显示了相应的响应。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#chats(lastMessagePreview())/$entity",
"id": "19:ebe3857aa388434bab0cad9d2e09f4de@thread.v2",
"topic": "Demo Group Chat",
"createdDateTime": "2021-04-08T16:00:53.563Z",
"lastUpdatedDateTime": "2022-09-08T23:11:54.246Z",
"chatType": "group",
"webUrl": "https://teams.microsoft.com/l/chat/19%3Aebe3857aa388434bab0cad9d2e09f4de%40thread.v2/0?tenantId=2432b57b-0abd-43db-aa7b-16eadd115d34",
"tenantId": "2432b57b-0abd-43db-aa7b-16eadd115d34",
"onlineMeetingInfo": null,
"createdBy": {
"application": null,
"device": null,
"user": {
"@odata.type": "#microsoft.graph.teamworkUserIdentity",
"id": "bfb5bb25-3a8d-487d-9828-7875ced51a30",
"displayName": null,
"userIdentityType": "aadUser",
"tenantId": "2432b57b-0abd-43db-aa7b-16eadd115d34"
}
},
"viewpoint": {
"isHidden": true,
"lastMessageReadDateTime": "2022-09-08T23:11:54.353Z"
},
"isHiddenForAllMembers": false,
"lastMessagePreview@odata.context": "https://graph.microsoft.com/beta/$metadata#chats('19%3Aebe3857aa388434bab0cad9d2e09f4de%40thread.v2')/lastMessagePreview/$entity",
"lastMessagePreview": {
"id": "1662678714353",
"createdDateTime": "2022-09-08T23:11:54.353Z",
"isDeleted": false,
"messageType": "systemEventMessage",
"from": null,
"body": {
"contentType": "html",
"content": "<systemEventMessage/>"
},
"eventDetail": {
"@odata.type": "#microsoft.graph.membersAddedEventMessageDetail",
"visibleHistoryStartDateTime": "0001-01-01T00:00:00Z",
"members": [
{
"id": "ee9f3754-62e1-4034-ad10-97940ef7f709",
"displayName": null,
"userIdentityType": "aadUser"
}
],
"initiator": {
"application": null,
"device": null,
"user": {
"id": "bfb5bb25-3a8d-487d-9828-7875ced51a30",
"displayName": null,
"userIdentityType": "aadUser"
}
}
}
}
}