获取 websocket 终结点

命名空间:microsoft.graph

允许你使用 socket.io 接收[驱动器][]和[列表][]的近实时[更改 socket.io。][] Socket.io 是 JavaScript 的热门通知库,它利用 WebSockets。 若要了解更多信息 ,请参阅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 正文中返回 响应代码和 subscription 对象。

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。

以下示例演示如何在 notificationUrl JavaScript 中将 与 socket.io 一起使用。

// this is the notificationUrl returned from this API
var notificationUrl = "https://f3hb0mpua.svc.ms/zbaehwg/callback?snthgk=1ff3-2345672zz831837523";

// 'io' comes from the socket.io client library
var socket = io(notificationUrl);

// 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));