首页 文章

使用microsoft graph beta从sharepoint站点获取工作簿

提问于
浏览
0

使用graph explorer,我想从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"
        }
    }
}

猜猜我接近使用上一个请求,但仍然无法弄清楚细节 .

Update:

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

1 回答

  • 0

    据我所知,有几个问题 .

    • GET / sharePoint / sites仅返回默认站点 . 因此,您必须使用sharePoint / sites / 进行额外调用才能访问相关网站 .

    • 在URL中使用基于SharePoint的完整"path"时,无法识别Excel API路径/工作簿 .

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

    解决方法:

    问题#1 . 您必须首先使用 GET /sharePoint:/{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 . 如果这不适合您,请告诉我 .

相关问题