【问题标题】:Accessing the shared documents folder within a private group of a sharepoint site using Graph API使用 Graph API 访问共享点站点的私有组中的共享文档文件夹
【发布时间】:2021-10-27 12:06:32
【问题描述】:

我正在尝试使用 Graph API 将测试文件上传到 Sharepoint 站点。我正在努力将 Graph API 正确指向私有组的 Shared Documents 文件夹中的某个点。

假设主机是 devsite.sharepoint.com,私有组是“Development”。在共享文档中有一个名为“TestFolder”的文件夹。

Private Group with folder "TestFolder"

通过图形资源管理器的反复试验,我已成功导航到使用的私人组。

https://graph.microsoft.com/v1.0/sites/devsite.sharepoint.com:/sites/Development

我尝试使用以下方法访问共享文档文件夹失败

https://graph.microsoft.com/v1.0/sites/devsite.sharepoint.com:/sites/Development/drive/root

https://graph.microsoft.com/v1.0/sites/devsite.sharepoint.com:/sites/Development/Shared%20Documents/TestFolder

全部返回

Code: BadRequestMessage: Url specified is invalid 要么 The provided path does not exist, or does not represent a site

不幸的是,图形 API 网站文档并没有产生任何有价值的东西,我们将不胜感激!

【问题讨论】:

    标签: azure microsoft-graph-api sharepoint-online


    【解决方案1】:

    您的第一次调用 https://graph.microsoft.com/v1.0/sites/devsite.sharepoint.com:/sites/Development:/drives 返回如下内容:

    {
        "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",
        "value": [
            {
                "createdDateTime": "2021-07-24T23:35:00Z",
                "description": "",
                "id": "b!A1234567-ZYXWVUTSRQPONMLKJIHGFEDCBA9876543210",
                "lastModifiedDateTime": "2021-08-12T16:39:23Z",
                "name": "Dokumente",
                "webUrl": "https://organizationname.sharepoint.com/sites/yourSIteName/folderName",
                "driveType": "documentLibrary",
                "createdBy": {
                    "user": {
                        "displayName": "abc"
                    }
                },
                "lastModifiedBy": {
                    "user": {
                        "email": "bla@organizationame.onmicrosoft.com",
                        "id": "12345678-4321-4321-4321-012345678901",
                        "displayName": "zz"
                    }
                },
                "owner": {
                    "group": {
                        "email": "x@y.onmicrosoft.com",
                        "id": "09876543-1234-1234-1234-012345678901",
                        "displayName": "Owner of something"
                    }
                },
                "quota": {
                    "deleted": 345678,
                    "remaining": 27487788453406,
                    "state": "normal",
                    "total": 27487790694400,
                    "used": 96120
                }
            }
        ]
    }
    

    上述json中description下的id参数就是你共享文档文件夹的drive-id。您可以像这样使用它来访问和导航您的共享文档文件夹:

    https://graph.microsoft.com/v1.0/sites/devsite.sharepoint.com/drives/b!A1234567-ZYXWVUTSRQPONMLKJIHGFEDCBA9876543210/root:/yourfile.docx
    

    【讨论】:

    • 感谢您的建议 - 工作愉快。在我将其标记为解决方案之前,有没有一种方法可以在不需要使用 drive-id 并且只使用相对路径的情况下实现?理想情况下,我希望这条路径能够自我记录,以便其他开发人员无需任何进一步的 cmets 就可以理解。类似:https://graph.microsoft.com/v1.0/sites/devsite.sharepoint.com:/sites/Development:/drives/Documents/root:/TestFolder/test.txt 这需要special 关键字吗?
    • 我花了很长时间来研究和解决您所描述的问题(对于我自己的应用程序)。似乎没有仅使用相对路径的解决方案,至少目前还没有。我对上面的解决方案很满意,因为虽然它需要额外的 http 请求,但如果需要,它仍然可以自动化。
    猜你喜欢
    • 2015-01-07
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    • 2020-10-07
    • 2018-10-31
    • 1970-01-01
    • 1970-01-01
    • 2011-02-23
    相关资源
    最近更新 更多