首页 > 解决方案 > GoogleDrive API 文件上传

问题描述

我正在尝试使用 Google Drive API 上传文件,即使在程序执行完成后,Google Drive 中也缺少该文件。

from Google import Create_Service
from googleapiclient.http import MediaFileUpload

Client_Secret = 'client_secret.json'
API_name = 'drive'
API_ver = 'v3'
Scope = ['https://www.googleapis.com/auth/drive']

service = Create_Service(Client_Secret,API_name,API_ver,Scope)


file_metadata = {'name': 'download.jpg'}
media = MediaFileUpload('./download.jpg', mimetype='image/jpeg')
file = service.files().create(body=file_metadata,
                                    media_body=media,
                                    fields='id').execute()
print ('File ID: %s' % file.get('status'))
                             

执行代码后,我可以在 Program 结束时获取 fileId。但无法在我的驱动器中找到上传文件。

client_secret.json-drive-v3-(['https://www.googleapis.com/auth/drive'],)
['https://www.googleapis.com/auth/drive']
drive service created successfully
File ID: 1UoTUr7kKh6fN_usX1FXOvCM4dbD2hx9e

有没有人遇到过这种问题...?

标签: python-3.xfile-uploadgoogle-apigoogle-oauth

解决方案


推荐阅读