获取 websocket 终结点
命名空间:microsoft.graph
重要
Microsoft Graph /beta
版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
不支持在生产应用程序中使用这些 API。
允许使用 socket.io 接收驱动器和列表的准实时更改通知。 Socket.io 是一个常用的 JavaScript 通知库,它利用 WebSocket。 若要了解详细信息,请参阅 socket.io。
权限
为此 API 选择标记为最低特权的权限。 只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
权限类型 | 最低特权权限 | 更高特权权限 |
---|---|---|
委派(工作或学校帐户) | Files.Read | Files.ReadWrite、Files.ReadWrite.All、Sites.ReadWrite.All |
委派(个人 Microsoft 帐户) | Files.Read | Files.ReadWrite、Files.ReadWrite.All |
应用程序 | 不支持。 | 不支持。 |
HTTP 请求
GET /me/drive/root/subscriptions/socketIo
GET /drives/{driveId}/root/subscriptions/socketIo
GET /drives/{driveId}/list/subscriptions/socketIo
GET /groups/{groupId}/drive/root/subscriptions/socketIo
GET /sites/{siteId}/lists/{listId}/drive/root/subscriptions/socketIo
示例
请求
GET /me/drive/root/subscriptions/socketIo
响应
如果成功,此方法在 200 OK
响应正文中返回响应代码和 订阅 对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"id": "opaqueId-fj3hd7yf283jfk193726nvc2w3i2diemdu8",
"notificationUrl": "https://f3hb0mpua.svc.ms/zbaehwg/callback?snthgk=1ff3-2345672zz831837523"
}
notificationUrl
返回的 是 socket.io 终结点 URL。
若要将其与 socket.io 客户端一起使用,请拆分令牌上的 /callback?
字符串。
之前 /callback?
字符串的部分是 socket.io 终结点 URL,字符串后面的部分是必须提供给库的不透明查询字符串。
以下示例演示如何在 JavaScript 中将 与 socket.io 配合使用 notificationUrl
。
// this is the notificationUrl returned from this API
var notificationUrl = "https://f3hb0mpua.svc.ms/zbaehwg/callback?snthgk=1ff3-2345672zz831837523";
// after the split, split[0] will be everything leading up to '/callback?' and split[1] will be everything after.
var split = notificationUrl.split("/callback?");
// 'io' comes from the socket.io client library
var socket = io(split[0], { query: split[1] });
// these examples log to the console.
// your app would provide its own callbacks
socket.on("connect", ()=>console.log("Connected!"));
socket.on("notification", (data)=>console.log("Notification!", data));
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈