【问题标题】:obtain item-id for microsoft graph api获取 microsoft graph api 的 item-id
【发布时间】:2021-07-19 09:38:47
【问题描述】:

我正在尝试弄清楚如何为 Microsoft graph API 的共享点站点中的文件获取“item-id”。

微软文档:https://docs.microsoft.com/en-us/graph/api/driveitem-get?view=graph-rest-1.0&tabs=http

这是我尝试过的:

尝试使用https://developer.microsoft.com/en-us/graph/graph-explorer 猜测可以让我下载所需文件的 api 链接。

我首先尝试像这样获取共享点站点:

https://graph.microsoft.com/v1.0/sites/omidtechnfr.sharepoint.com:/sites/delploy

成功了:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites/$entity",
    "createdDateTime": "2021-07-15T21:02:02.78Z",
    "description": "delploy",
    "id": "omidtechnfr.sharepoint.com,5e03397e-03b0-4d92-9658-f9163f0131b3,1d9f21da-4d74-45db-b5d4-e4a7f7f278a1",
    "lastModifiedDateTime": "2021-07-17T02:16:39Z",
    "name": "delploy",
    "webUrl": "https://omidtechnfr.sharepoint.com/sites/delploy",
    "displayName": "delploy",
    "root": {},
    "siteCollection": {
        "hostname": "omidtechnfr.sharepoint.com"
    }
}

然后我尝试使用我认为是 SharePoint 网站 delploy 的项目 ID 来尝试从该网站获取更多信息,以便我可以尝试找到我想要下载的文件的 item-id

https://graph.microsoft.com/v1.0/sites/5e03397e-03b0-4d92-9658-f9163f0131b3/drive/

我得到了一些结果,但它没有让我对它做任何事情的 item-id:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives/$entity",
    "createdDateTime": "2021-07-11T05:16:50Z",
    "description": "",
    "id": "b!fjkDXrADkk2WWPkWPwExs9ohnx10TdtFtdTkp_fyeKF_K1_Z49FFSbzXVFRA5GKa",
    "lastModifiedDateTime": "2021-07-16T18:32:35Z",
    "name": "Documents",
    "webUrl": "https://omidtechnfr.sharepoint.com/sites/delploy/Shared%20Documents",
    "driveType": "documentLibrary",
    "createdBy": {
        "user": {
            "displayName": "System Account"
        }
    }

此时我开始变得绝望和有点生气。所以我试着从sharepoint下载文件,并假设下载链接末尾的字符是item-id,但这也不起作用: 下载链接:

https://omidtechnfr.sharepoint.com/sites/delploy/_layouts/15/download.aspx?UniqueId=25e2fd4f%2Deb32%2D43ac%2D9141%2Dfa47a610a27c

使用https://www.urldecoder.org/ 解码我假设是我要下载的文件的item-id

25e2fd4f-eb32-43ac-9141-fa47a610a27c

然后试图拼命地将它附加到 Microsoft graph api 上,看看会发生什么:

https://graph.microsoft.com/v1.0/sites/5e03397e-03b0-4d92-9658-f9163f0131b3/drive/items/25e2fd4f-eb32-43ac-9141-fa47a610a27c

它失败了:

{
    "error": {
        "code": "itemNotFound",
        "message": "The resource could not be found.",
        "innerError": {
            "date": "2021-07-17T14:13:51",
            "request-id": "985e2893-5343-47ac-a93c-6629a00c4eb3",
            "client-request-id": "73a3b6d0-f1ce-bb51-b126-43f0957d15e3"
        }
    }
}

【问题讨论】:

    标签: sharepoint microsoft-graph-api


    【解决方案1】:

    您可以通过路径获取文件:https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root:/{item-path}

    例如:https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root:/test.docx

    如果文件在文件夹中,则为:https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root:/folder1/test.docx

    【讨论】:

    • 这就是答案。我在 microsoft graph 网站上试过这个,它返回了下载的实际 url。然后我添加了?select=d,@microsoft.graph.downloadUrl,这给了我一个很棒的 url 链接。然而,我意识到我现在面临一个完全不同的问题。我必须弄清楚如何仅使用 curl 对 Microsoft graph api 进行身份验证。我可以使用 microsoft graph powershell 和我的应用注册信息(如应用 ID、租户 ID 等)来执行此操作。但是我不知道如何为 curl 执行此操作。继续进行更多研究。感谢您的帮助。
    猜你喜欢
    • 2020-07-21
    • 1970-01-01
    • 2023-04-06
    • 2023-01-01
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多