使用 Microsoft Graph Beta 从 SharePoint 站点获取工作簿

Get workbook from sharepoint site using microsoft graph beta

使用图形资源管理器,我想从 SharePoint 站点的 Excel 文件中获取数据

从 Onedrive(用于商业)这有效: graph.microsoft.com/beta/me/drive/root:/Map1.xlsx:/workbook/worksheets

来自 SharePoint 网站没有: graph.microsoft.com/beta/sharepoint:/MyFabulousSite/MyDocLib/Map1.xlsx:/Workbook/worksheets 回应:

状态码:400

{
    "error": {
        "code": "BadRequest",
        "message": "Resource not found for the segment 'Workbook'.",
        "innerError": {
            "request-id": "160a545b-66b8-44fc-92b7-f2b327824b84",
            "date": "2017-01-25T16:20:02"
        }
    }
}

这个也试过了,也没用: graph.microsoft.com/beta/sharePoint/sites/ce33044e-6360-4630-9c5f-afad46f88333,cb1e4d7e-24be-433c-a874-12551cdd3348/drives/b!TBQzzmBjMEacX6-tRviDM3FNHsu-JxxDqHQSVRzdM0hfFOUPQwasQb407ORQaT2q/root:/Map1.xlsx:/workbook/worksheets 回应:

Status Code: 500
{
    "error": {
        "code": "-1, Microsoft.SharePoint.Client.UnknownError",
        "message": "Onbekende fout",
        "innerError": {
            "request-id": "cec7663e-b708-4887-8d82-87d59fb15a2b",
            "date": "2017-01-25T16:16:58"
        }
    }
}

猜猜我使用最后一个请求更接近了,但仍然无法弄清楚细节。

更新:

将我的 Excel 文件移动到默认库中的根站点,我可以使用以下 url 请求工作表: graph.microsoft.com/beta/sharePoint/site/drive/root:/Test.xlsx:/workbook/worksheets

据我所知,有几个问题。

  1. GET /sharePoint/sites 仅 returns 默认站点。因此,您必须进行额外的调用才能使用 sharePoint/sites/{id} 访问相关站点。
  2. 当您在 URL 中使用完全基于 SharePoint 的 "path" 时,无法识别 Excel API 路径 /workbook。

因此,作为解决方法,您必须浏览站点 ID 并在 URL 中进行驱动。在问题得到解决之前,您无法使用完整站点 Sharepoint 路径访问 Excel 文件并使用 Excel API。

解决方法:

对于第 1 期。您必须首先使用 GET /sharePoint:/{path}:/,其中 {path} 是站点的路径(不是文件或文件夹),然后获取站点 id 属性。 示例:

GET https://graph.microsoft.com/beta/sharepoint:/exceltest:/?$select=id

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#baseItem",
    "@odata.type": "#microsoft.graph.site",
    "id": "48d4a189-be5d-497a-9a6d-b971db377a5c,3a201b6c-798f-4e6a-a805-9e67fdf1c8ce"
}

对于#2。现在使用返回的 id 通过使用以下方法之一转到文件所在的驱动器:

GET /sharePoint/sites/{id}/drive/root/items/{fileId}/workbook
GET /sharePoint/sites/{id}/drive/root:/{file-path}:/workbook

GET /sharePoint/sites/{id}/drives/{driveId}/root/items/{fileId}/workbook
GET /sharePoint/sites/{id}/drives/{driveId}/root:/{file-path}:/workbook

我可以使用我的开发人员租户通过此解决方法访问 Excel API。如果这对您不起作用,请告诉我。