我写了一个代码将文件从本地PC上传到我的gmail驱动器,为此我获得了访问令牌,这是我的代码,可以正常工作,但是令牌在短时间后过期:
def upload_1():
headers = {"Authorization": "Bearer #acess token"} #put ur access token after the word 'Bearer '
qassam = glob.glob("/root/Downloads/*.pdf")
for i in qassam:
qassam = "\n".join(qassam)
print i
para = {
"name": (i), #file name to be uploaded
"parents": ["folderid"] # make a folder on drive in which you want to upload files; then open that folder; the last thing in present url will be folder id
}
files = {
'data': ('metadata', json.dumps(para), 'application/json; charset=UTF-8'),
'file': ('application/zip',open(i, "rb")) # replace 'application/zip' by 'image/png' for png images; similarly 'image/jpeg' (also replace your file name)
}
r = requests.post(
"https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart",
headers=headers,
files=files
)
print(r.text)
upload_1()
无论如何,过期后是否有刷新我的访问令牌而无需打开网页和.... etc的意思,我的意思是我需要从python进行操作