【问题标题】:MS Graph API Sharepoint GetDriveItemMS Graph API 共享点 GetDriveItem
【发布时间】:2021-01-13 21:14:40
【问题描述】:

Microsoft Graph API 快把我逼疯了。我尝试阅读了几个小时,但仍然无法正常工作。

我使用 Sharepoint,其中包含一个子站点,其中有包含多个文件夹的 DocumentLibrary。

我搜索API:(https://graph.microsoft.com/v1.0/search/query)

                   "hits": [
                        {
                            "hitId": "01XPDM72T7SCIOG6BP4BAYQ5QI5RFFAESK",
                            "rank": 1,
                            "summary": "<c0>test</c0><ddd/><c0>test</c0><ddd/>",
                            "resource": {
                                "@odata.type": "#microsoft.graph.driveItem",
                                "size": 4,
                                "id": "3",
                                "createdDateTime": "2021-01-08T12:11:12Z",
                                "lastModifiedDateTime": "2021-01-08T12:11:12Z",
                                "name": "test.txt",
                                "webUrl": "https://tenant.sharepoint.com/sites/SubSite/Gedeelde documenten/test.txt",
                                "fileSystemInfo": {
                                    "createdDateTime": "2021-01-08T12:11:12Z",
                                    "lastModifiedDateTime": "2021-01-08T12:11:12Z"
                                },
                                "lastModifiedBy": {
                                    "user": {
                                        "displayName": "Admin"
                                    }
                                },
                                "parentReference": {
                                    "driveId": "2",
                                    "siteId": "1",
                                    "sharepointIds": {
                                        "listId": "[snip]",
                                        "listItemUniqueId": "[snip]"
                                    }
                                }
                            }
                        },

到目前为止一切顺利。我找到了一个driveItem,现在想获取内容。

在 parentReference 中,我在资源中看到 driveId、siteId 和 id。 据我所知:

{site-id} = 1;
{drive-id} = 2;
{item-id} = 3;

如果我查看https://docs.microsoft.com/en-us/graph/api/driveitem-get,我可以使用多个函数。

我从/sites/{site-id}/drive/items/{item-id}/drives/{drive-id}/items/{item-id}开始

回应: "error": { "code": "itemNotFound", "message": "The resource could not be found.",

/sites/{site-id}/lists/{list-id}/items/{item-id}/driveItem

回复:

"error": { "code": "itemNotFound", "message": "The specified list was not found",

没有任何作用。 有人可以帮帮我吗?

【问题讨论】:

    标签: sharepoint microsoft-graph-api


    【解决方案1】:

    请首先使用此端点获取有效的站点 ID:

    https://graph.microsoft.com/v1.0/sites?search=yoursitename,站点 id 不应该是 int 值,应该是这样的:

    然后像这样访问特定的库:

    https://graph.microsoft.com/v1.0/sites/TenantName.sharepoint.com,91a47a59-db5e-4d17-a689-479ee8905533,274459c9-4c96-42bf-9b96-838ffa387aaa/lists/doc2/items/10/driveItem
    

    该库被命名为“doc2”并获取项目id“10”:

    【讨论】:

    • 确实我删除了 siteId。
    • 我试过这个,但它不起作用。找不到列表 (itemNotFound)。名字是“Gedeelde documenten”。模板文档库。但没有任何效果:(
    • 使用 Graph API Explorer 时,我得到输出:/sites/[siteId]/lists/e2263f16-8382-4097-a1ed-70bac7ba752c/items/160 我现在得到一个文件的内容。在 PHP 中使用 Graph API 时,我得到:“error”:{“code”:“itemNotFound”,“message”:“找不到指定的列表”,我卡住了
    • 所以你现在可以使用Graph Explorer获取有效的内容,即表示请求有效。如果要在 PHP 中调用,可以使用这个 sdk:github.com/microsoftgraph/msgraph-sdk-php
    猜你喜欢
    • 2020-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-12
    • 2022-11-09
    • 2018-03-23
    • 1970-01-01
    • 2021-10-27
    相关资源
    最近更新 更多