我正在编写一个脚本,使用 Microsoft Graph API 1.0 将文件上传到文件夹。我正在尝试这样做,以便运行脚本的用户可以复制并粘贴 sharepoint/onedrive 文件夹的路径。我当然也想使用路径作为要上传的文件的目的地。到目前为止,我找不到使它起作用的方法。
路径示例:https://example.sharepoint.com/sites/TheSite/Shared%20Documents/User
API 引用:https://learn.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0
我已尝试使用路径、部分路径以及主机名和路径的每个变体对 API 进行 GET 调用。我正在使用 Python Requests 库,身份验证不是问题。
收到的错误:
"error": {
"code": "itemNotFound",
"message": "The resource could not be found."
和
"error": {
"code": "invalidRequest",
"message": "Invalid hostname for this tenancy",
最佳答案
当我们在使用存储路径时。我们必须选择完整的调用路径。无论是 Azure blob 容器还是 Sharepoint 或 Drive。
请引用以下链接上传数据
https://learn.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http https://medium.com/@rahul.metangale/upload-a-file-to-sharepoint-using-azure-graph-api-9deacce57449
上传步骤:
1)生成 token - 使用租户、客户端 ID、客户端密码
2)获取驱动器id 获取 https://graph.microsoft.com/v1.0/drives
3)上传小于4MB的文件: 放https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/content header : “授权”:“不记名 正文:二进制(在 postman 正文中选择二进制选项) 使用选择文件选项上传文件 file-name:是文件名加上扩展名例如:test.txt
4)上传文件大于4MB 获取:https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/createUploadSession header : “授权”:“不记名 这将返回上传网址 上传文件 放 header : “授权”:“不记名 正文:二进制(在 postman 正文中选择二进制选项) 4)上传大于4MB的文件: header : “授权”:“不记名
关于sharepoint - 如何使用文件夹路径和 Microsoft Graph API 1.0 上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63273442/