MS Graph - 尝试创建上传会话但找不到共享文档库的资源错误

MS Graph - trying to create an upload session but getting resource not found error for shared document library

问题

我有一个 Sharepoint 文档库,位于:

https://my-dough-main.sharepoint.com/widgets/Shared%20Documents/Forms/AllItems.aspx

我正在尝试以编程方式(在 c# 中)创建上传会话。但是我收到错误消息“找不到资源”

代码

 private readonly siteName string = "my-dough-main.sharepoint.com:/sites/widgets:";
 private readonly string largeBlobsDocumentLibraryID = "57575757575-1ccc-4a44-b88e-5ef0fb75249b";

 // Create the upload session
 //https://docs.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0
 // itemPath does not need to be a path to an existing item
 var uploadSession =  await _graphServiceClient.Site[siteName.]Drives[largeBlobsDocumentLibraryID]
     .ItemWithPath("thebogusfile.mp4")
     .CreateUploadSession(uploadProps)
     .Request()
     .PostAsync();

至于我是如何获得 ID 的,我在 Graph Explorer 中 运行 这个查询:

 https://graph.microsoft.com/v1.0/sites/my-dough-main.sharepoint.com:/sites/widgets:/Drives

在结果集中,我抓取了“共享文档”库的 ID。

    {
        "createdDateTime": "2021-11-07T05:30:15Z",
        "description": "",
        "id": "this is the value I'm trying",
        "lastModifiedDateTime": "2021-11-24T13:54:18Z",
        "name": "Documents",
        "webUrl": "https://my-dough-main.sharepoint.com/sites/widgets/Shared%20Documents",
        "driveType": "documentLibrary",
        "createdBy": {
            "user": {
                "displayName": "System Account"
            }
        },
        "lastModifiedBy": {
            "user": {
                "email": "jdoe@outlook.com",
                "id": "guid",
                "displayName": "Doe john"
            }
        },
        "owner": {
            "user": {
                "email": "jdoe@outlook.com",
                "id": "guid",
                "displayName": "Doe John"
            }
        },
        "quota": {
            "deleted": 0,
            "remaining": 27485528222812,
            "state": "normal",
            "total": 27487790694400,
            "used": 2262471588
        }
    },

谁能告诉我我误入歧途的地方?到目前为止我看到的所有示例都使用 Me 位置,但是您如何写入其他位置? 谢谢

获得 id 后,尝试 运行 在图形资源管理器中进行以下查询。检查你是否可以得到图书馆。

https://graph.microsoft.com/v1.0/drives/{drvie-id}

如果你能得到这个库,那么把你的代码改成这样:

var uploadSession =await graphClient.Drives["{drive-id}"].Root
     .ItemWithPath("thebogusfile.mp4")
     .CreateUploadSession()
     .Request()
     .PostAsync();