首页 > 解决方案 > Python 谷歌驱动 API

问题描述

您好,我想使用 OAuth 3.0 Playground 将图像上传到 Google Drive。它有效,但每 3600 秒访问令牌就会更改一次。有谁知道更新令牌的方法,甚至是完全不同的方法。我还需要驱动器中的图像 ID,直到现在我使用返回函数。

headers = {"Authorization": "Bearer ###Acesstoken from Playground###"} 
para = {
    "name": "" + str(img_counter) + ".png", #file name to be uploaded
    "parents": ["###Folder id###"] 
}
files = {
    'data': ('metadata', json.dumps(para), 'application/json; charset=UTF-8'),
    'file': open("./Test.png", "rb") 
}
r = requests.post(
    "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart",
    headers=headers,
    files=files
    
)

return(r.text)

标签: pythonapi

解决方案


推荐阅读