簡體   English   中英

使用Microsoft Graph API獲取SharePoint文件夾和文檔

[英]Get SharePoint folders and docs using Microsoft Graph API

我正在嘗試使用Microsoft Graph API從SharePoint文檔庫中獲取文件夾和文檔。

如果我對https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com:/sites/MyDocumentSite:/drives/進行GET請求, https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com:/sites/MyDocumentSite:/drives/得到以下信息:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",
    "value":[
        {
            "createdDateTime": "2019-09-05T07:09:49Z",
            "description": "",
            "id": "b!wxh2ZWwoT0KKTdLRYjD5jvzjo8jkat5LgY3VyfgEqkv3YVg_XXXXXXXXXXXXXXXX",
            "lastModifiedDateTime": "2019-09-05T07:09:49Z",
            "name": "Documents",
            "webUrl": "https://mysite.sharepoint.com/sites/MyDocumentSite/Shared%20Documents",
            "driveType": "documentLibrary",
            "createdBy":{"user":{"displayName": "System Account" }},
            "lastModifiedBy":{"user":{"email": "me@myorganization.org", "id": "73f9990c-5c92-4839-8b13-XXXXXXXXXXXX", "displayName": "John Smith"…},
            "quota":{"deleted": 0, "remaining": 0, "total": 0, "used": 0}
        }
    ]
}

但是,如果我嘗試通過對該ID執行GET請求來訪問該驅動器: https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com:/sites/MyDocumentSite:/drives/b!wxh2ZWwoT0KKTdLRYjD5jvzjo8jkat5LgY3VyfgEqkv3YVg_XXXXXXXXXXXXXXXX : https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com:/sites/MyDocumentSite:/drives/b!wxh2ZWwoT0KKTdLRYjD5jvzjo8jkat5LgY3VyfgEqkv3YVg_XXXXXXXXXXXXXXXX :/ https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com:/sites/MyDocumentSite:/drives/b!wxh2ZWwoT0KKTdLRYjD5jvzjo8jkat5LgY3VyfgEqkv3YVg_XXXXXXXXXXXXXXXX MyDocumentSite: https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com:/sites/MyDocumentSite:/drives/b!wxh2ZWwoT0KKTdLRYjD5jvzjo8jkat5LgY3VyfgEqkv3YVg_XXXXXXXXXXXXXXXX drives/b! https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com:/sites/MyDocumentSite:/drives/b!wxh2ZWwoT0KKTdLRYjD5jvzjo8jkat5LgY3VyfgEqkv3YVg_XXXXXXXXXXXXXXXX ,出現BadRequest錯誤:

{
    "error":{
        "code": "BadRequest",
        "message": "Url specified is invalid.",
        "innerError":{
            "request-id": "7c9eaf61-764f-4d72-abdb-ffa2fe868e90",
            "date": "2019-09-16T19:09:41"
        }
    }
}

最終,我想要一種顯示文檔庫中所有文件夾和文檔的方法,但似乎無法超越這一初始步驟。

獲得要查詢的驅動器ID后,請在根目錄下使用/ drives發出請求:

https://graph.microsoft.com/v1.0/drives/<driveId>

使用“增量” API: https : //docs.microsoft.com/zh-cn/graph/api/driveitem-delta?view=graph-rest-1.0&tabs=http

第一次調用將返回所有項目。 (如果有分頁,則需要調用nextLink,直到收到deltaLink為止)。

您可能需要使用GET / sites / {siteId} / drive / root / delta或GET / drives / {drive-id} / root / delta之一

確實,當站點通過站點路徑尋址時,以下查詢將失敗,但例外:

GET `https://graph.microsoft.com/v1.0/sites/{hostname}:/{server-relative-path}/drive/root/children` 

由於類似的查詢,但這似乎是一個錯誤 ,但是當站點通過id尋址時,按預期方式工作:

GET https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root/children

要考慮的另一種選擇,是通過其標識符(不指定站點路徑或標識符)來獲取Drive資源,例如:

GET https://graph.microsoft.com/v1.0/drives/{drive-id}/root/children

輪到在庫中獲取所有文檔和文件夾時, List children of a driveItem終結點的List children of a driveItem僅在當前文件夾下返回1級。

要返回所有驅動器項目,您至少可以考慮:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM