在上传会话中无法从Microsoft Graph获取UploadURL

问题描述 投票:0回答:1

我一直在尝试使用python实现以下过程

https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession?view=odsp-graph-online#create-an-upload-session

我一直在尝试获取上传URL部分

请注意,我已经获得了访问令牌并创建了所需的客户端ID和密码

    def getUploadUrl(filename="test.txt"):
        global token
        if (not token):
            with open('token.json', 'r') as f:
                token = json.load(f)
        if (token["expires_at"] < time.time()):
            refreshToken()
        location = "/me/drive/root:/FolderA/" + filename + ":/createUploadSession"
        client = OAuth2Session(client_id=client_id,
                               redirect_uri=REDIRECT_URI, token=token)

        headers = {'Content-Type': 'application/json'}

        json_file = {
            "item": {"@odata.type": "microsoft.graph.driveItemUploadableProperties",
                "@microsoft.graph.conflictBehavior": "replace",
                "name": filename
            }
        }
        json_string = json.dumps(json_file, indent=4)
        r = client.post(BaseUrl + location,
                        data=json_string, headers=headers)
        print(r.status_code)
        print(r.text)
        upload_url = ""
        if(r.status_code == 200):
            upload_url = r.json()['uploadUrl']
            return upload_url, r
        else:
            return "", ""

尽管我仍然收到以下错误响应

{
 "error": {
  "code": "invalidRequest",
   "message": "Invalid request",
    "innerError": {
     "request-id": "7893d0aa-fcdb-46bc-b0b6-58fd90c4cb46",
      "date": "2020-03-21T17:15:13"
    }
  }
python-3.x file-upload oauth-2.0 microsoft-graph onedrive
1个回答
0
投票

我最终直到现在所做的只是删除JSON有效负载中的@odata.type": "microsoft.graph.driveItemUploadableProperties

© www.soinside.com 2019 - 2024. All rights reserved.