如何对 Microsoft 组和团队的名称进行编码以将它们包含在 API 调用 URL 中?

How do I encode the names of Microsoft group and teams names to include them in an API call URL?

如果我有一个 ID 为 "testteam@example.onmicrosoft.com" 的 Office 365 Group/Microsoft 团队,并且我想使用 this 等 Beta API 之一查询它,我需要查询 URL 例如 https://graph.microsoft.com/beta/groups/{id}/threads。但是,我坚持对团队名称进行编码。 https://graph.microsoft.com/beta/groups/testteam@example.onmicrosoft.com/threadshttps://graph.microsoft.com/beta/groups/testteam@example%2Eonmicrosoft%2E/threadshttps://graph.microsoft.com/beta/groups/testteam@example/threadshttps://graph.microsoft.com/beta/groups/"testteam@example"/threads,https://graph.microsoft.com/beta/groups/"testteam@example.onmicrosoft.com"/threads都是return下面的错误

"error": {
    "code": "Request_BadRequest",
    "message": "Invalid object identifier 'whatever_I_entered'."

据我了解,这只是常规 URL 编码。例如在 JS 中你可以使用函数 encodeURIComponent(str)。如果你想尝试使用 online URL encoder. For example encoded version of testteam@example.onmicrosoft.com will looks like testteam%40example.onmicrosoft.com and your graph request would be <a href="https://graph.microsoft.com/beta/groups/testteam%40example.onmicrosoft.com/threads" rel="nofollow noreferrer">https://graph.microsoft.com/beta/groups/testteam%40example.onmicrosoft.com/threads</a>

编辑:

在请求中您需要使用组的 Id。例如:Get Group 请求可能看起来像 ... 组 ID 是 c28c1cc9-e1ab-4c4d-98d1-d8fdf128b60f

https://graph.microsoft.com/v1,0/groups/c28c1cc9-e1ab-4c4d-98d1-d8fdf128b60f?$select=description,allowExternalSenders