我正在尝试与Google Drive API进行交互,并且在他们的示例正在工作时,我想了解如何在python中创建POST请求,而不是使用其预先写好的方法。例如,在python中,我将如何发出发布请求来插入文件? Insert a FileGoogle Drive API POST请求?
如何将请求和参数添加到主体?
谢谢!
更新1:
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + 'my auth token'}
datax = {'name': 'upload.xlsx', 'parents[]': ['0BymNvEruZwxmWDNKREF1cWhwczQ']}
r = requests.post('https://www.googleapis.com/upload/drive/v3/files/', headers=headers, data=json.dumps(datax))
response = json.loads(r.text)
fileID = response['id']
headers2 = {'Authorization': 'Bearer ' + 'my auth token'}
r2 = requests.patch('https://www.googleapis.com/upload/drive/v3/files/' + fileID + '?uploadType=media', headers=headers2)
检查此相关的[SO问题](http://stackoverflow.com/questions/20942626/filesinsert-google-drive-sdk-python-example-what-is-drive-api-service-ins?rq=1 ),我想它可以给你一个关于POST请求的想法 –