[英]How to upload files using folder path and Microsoft Graph API 1.0
我正在编写一个脚本以使用 Microsoft Graph API 1.0 将文件上传到文件夹。 我正在尝试这样做,以便运行脚本的用户可以复制和粘贴 sharepoint/onedrive 文件夹的路径。 我当然也想将路径用作要上传的文件的目的地。 到目前为止,我找不到一种方法来让它工作。
路径示例: https://example.sharepoint.com/sites/TheSite/Shared%20Documents/User
API 参考: https://docs.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0
我尝试使用路径、部分路径以及主机名和路径的每个变体对 API 进行 GET 调用。 我正在使用 Python 请求库,身份验证不是问题。
收到的错误:
"error": {
"code": "itemNotFound",
"message": "The resource could not be found."
和
"error": {
"code": "invalidRequest",
"message": "Invalid hostname for this tenancy",
当我们使用存储路径时。 我们必须选择完整的调用路径。它是 Azure blob 容器还是 Sharepoint 或驱动器。
请参考以下链接上传数据
https://docs.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)生成令牌 - 使用租户、客户端 ID、客户端密码
2)获取驱动器ID GET https://graph.microsoft.com/v1.0/drives
3)上传小于4MB的文件:PUT https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/content Header: “授权”:“承载正文:二进制(在邮递员的正文中选择二进制选项)使用select文件选项上传文件文件名:是文件名和扩展名示例:test.txt
4)上传大于4MB的文档 GET: https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/createUploadSession Header: “Authorization”: “Bearer This will return upload url Upload Document PUT Header: “Authorization”: “Bearer Body: binary (select binary option in body in postman) 4)Upload Document Greater than 4MB: Header: “Authorization”: “Bearer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.