我正在嘗試與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請求的想法 –