Microsoft Graph API:是否可以递归遍历文件夹

Microsoft Graph API : Is it possible to traverse recursive over Folders

我们正在从邮件 EWS 转换为 Microsoft office 365 Graph API、

我想将我所有的文件夹树展开到平面文件夹列表中,因此列表中的每个条目都应包含:

Folder:{parentId, myId} , ...

我在测试版中看到有一个遍历选项:

https://graph.microsoft.com/beta/me/mailFolders/inbox?$top=50&$expand=childFolders($levels=5)

可惜我只拿到了第一关...

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#users('4ed9f9bf-cfea-47de-ba2c-e4323d2dd600')/mailFolders/$entity",
    "id": "AQMkAGM5MDIzODk0LTg2NgBjLTQxN2EtOTNmMC0wYWY4M2VkMTg1MWEALgAAAxfTs4ItP_BBtfaokkhWqiMBAJ1RfNBJd7VOqHUq_F8aPdIAAAIBDQAAAA==",
    "displayName": "Inbox",
    "parentFolderId": "AQMkAGM5MDIzODk0LTg2NgBjLTQxN2EtOTNmMC0wYWY4M2VkMTg1MWEALgAAAxfTs4ItP_BBtfaokkhWqiMBAJ1RfNBJd7VOqHUq_F8aPdIAAAIBCQAAAA==",
    "childFolderCount": 1,
    "unreadItemCount": 307,
    "totalItemCount": 320,
    "wellKnownName": "inbox",
    "childFolders@odata.context": "https://graph.microsoft.com/beta/$metadata#users('4ed9f9bf-cfea-47de-ba2c-e4323d2dd600')/mailFolders('AQMkAGM5MDIzODk0LTg2NgBjLTQxN2EtOTNmMC0wYWY4M2VkMTg1MWEALgAAAxfTs4ItP_BBtfaokkhWqiMBAJ1RfNBJd7VOqHUq_F8aPdIAAAIBDQAAAA%3D%3D')/childFolders",
    "childFolders": [
        {
            "id": "AAMkAGM5MDIzODk0LTg2NmMtNDE3YS05M2YwLTBhZjgzZWQxODUxYQAuAAAAAAAX07OCLT-gQbX2qJJIVqojAQCdUXzQSXe1Tqh1KvhfGj3SAAOojCnvAAA=",
            "displayName": "LEVEL_1",
            "parentFolderId": "AQMkAGM5MDIzODk0LTg2NgBjLTQxN2EtOTNmMC0wYWY4M2VkMTg1MWEALgAAAxfTs4ItP_BBtfaokkhWqiMBAJ1RfNBJd7VOqHUq_F8aPdIAAAIBDQAAAA==",
            "childFolderCount": 1,
            "unreadItemCount": 0,
            "totalItemCount": 0,
            "wellKnownName": null
        }
    ]
}

有没有好的 API O-Data 或其他遍历算法(如 EWS - 深度遍历),这样我就可以减少休息 API 调用 ...

谢谢=]

Microsoft Graph API 中没有深度文件夹遍历调用。您将需要扩展每个级别。你可能想为此打开一个feature request

话虽如此,您可以使用 batch feature to reduce the number of calls you have to make to get the folder hierarchy. You could have a single batch call to get all folders at a given level across hierarchies as long as the folder hierarchy isn't wider than 20 folders at any level (see batch restrictions)。您想要在任何级别考虑超过 20 个文件夹。

关于执行此操作的算法,我还没有看到这种情况,因此您可能是 Microsoft Graph 深层文件夹遍历批处理算法的鼻祖。

我在 中找到了这个答案,我认为这是在平面列表中递归检索所有邮件文件夹和子文件夹的最简单方法。

Yes, you can. Simply use delta query to get all the folders.

Request Example: https://graph.microsoft.com/v1.0/users/[user_id]/mailfolders/delta?$select=displayname You get an array of all the folders, with child folders just after the parent-folder item in the response.

Test: Go to : https://developer.microsoft.com/en-us/graph/graph-explorer GET Version: v1.0 URL: https://graph.microsoft.com/v1.0/me/Mailfolders/delta Run Query

Notice "Internal Screens" and "Project Falcon" folders whose parentFolderId is the ID of "Inbox" are also included in the response.