python - 在没有浏览器活动的情况下使用 Python API 在 Google 驱动器上上传文件
问题描述
我正在使用 Google Drive API 上传视频,然后获取该视频的 URL。
这是我尝试上传文件的代码:
SCOPES = ['https://www.googleapis.com/auth/drive.file']
flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
# Now build our api object, thing
drive_api = build('drive', 'v3', credentials=creds)
file_metadata = {
'name': 'Test file',
# 'mimeType': 'application/vnd.google-apps.spreadsheet'
}
media = MediaFileUpload('/path/to/file',
mimetype='text/text',
resumable=True)
file = drive_api.files().create(body=file_metadata,
media_body=media,
fields='id').execute()
print('File ID: %s' % file.get('id'))
我的最终目标是通过服务器上的一些调度程序在 Google Drive 上上传文件。
我还尝试了上传文件的教程。
但是上面的代码和教程总是打开浏览器并获得权限。我想在没有浏览器活动的情况下上传文件。
如何在没有浏览器活动的情况下上传文件,例如仅使用api_key
或client_id
等?
解决方案
推荐阅读
- sql - ORA-01802: 尽管 select 语句不包括日期操作,但 Julian 日期超出范围
- git - Git:我可以将更改从一个分支移动到另一个分支吗?
- c - 如何从原始堆栈复制堆栈
- flutter - 多个 WebView 重新加载问题 Flutter
- python - python 使用azure devops api时出错“API资源位置未注册”
- arrays - 如何遍历 ReactTable 中的对象数组以显示数据?
- ignite -
无法运行查询 - python - 将范围表达式更改为列表的 Pythonic 方法
- excel - 如何复制不连续的列并复制除前 2 行和最后 1 行之外的所有内容而不剪切?当行数很多时,剪切需要很长时间
- html - 最后一个孩子/最后一个类型不能在 div 上工作