有什么方法可以让 GoogleDriveAPI 支持导出 MIME 类型列表在 python 或 ruby 中?
It there any way to get GoogleDriveAPI supported export MIME types list in python or ruby?
在通过GoogleDriveAPI 上传文件到GooogleDrive 之前,我想检查GoogleDriveAPI 是否支持该文件的mime 类型。
https://developers.google.com/drive/api/v3/ref-export-formats
我们可以通过使用包含所有手动输入的 mime 类型的数组来做到这一点,但如果有任何聪明的方法,我想使用它。
我相信你的目标如下。
- 您想检索 Google 驱动器的导出格式的值。
- 您想使用 googleapis 实现 ruby 和 python。
在这种情况下,我想在Drive API中使用“About:get”的方法。 ruby和python的示例脚本如下。
示例脚本:Ruby
service = Google::Apis::DriveV3::DriveService.new
service.authorization = authorize
res = service.get_about(fields: '*') # or service.get_about(fields: 'exportFormats')
export_formats = res.export_formats
puts export_formats
示例脚本:Python
service = build('drive', 'v3', credentials=creds)
res = service.about().get(fields='*').execute() # or service.about().get(fields='exportFormats').execute()
export_formats = res['exportFormats']
print(export_formats)
注:
- 此示例脚本使用 Drive API v3.
- 在这种情况下,您也可以使用
exportFormats
的值代替 *
作为字段。
- 在此答案中,假设您已经能够使用驱动器 API 从 Google 驱动器获取值。请注意这一点。
- 顺便说一句,比如当你想取回
importFormats
的值时,请将export_formats = res.export_formats
和export_formats = res['exportFormats']
修改为import_formats = res.import_formats
和import_formats = res['importFormats']
, 分别.
参考:
在通过GoogleDriveAPI 上传文件到GooogleDrive 之前,我想检查GoogleDriveAPI 是否支持该文件的mime 类型。 https://developers.google.com/drive/api/v3/ref-export-formats
我们可以通过使用包含所有手动输入的 mime 类型的数组来做到这一点,但如果有任何聪明的方法,我想使用它。
我相信你的目标如下。
- 您想检索 Google 驱动器的导出格式的值。
- 您想使用 googleapis 实现 ruby 和 python。
在这种情况下,我想在Drive API中使用“About:get”的方法。 ruby和python的示例脚本如下。
示例脚本:Ruby
service = Google::Apis::DriveV3::DriveService.new
service.authorization = authorize
res = service.get_about(fields: '*') # or service.get_about(fields: 'exportFormats')
export_formats = res.export_formats
puts export_formats
示例脚本:Python
service = build('drive', 'v3', credentials=creds)
res = service.about().get(fields='*').execute() # or service.about().get(fields='exportFormats').execute()
export_formats = res['exportFormats']
print(export_formats)
注:
- 此示例脚本使用 Drive API v3.
- 在这种情况下,您也可以使用
exportFormats
的值代替*
作为字段。 - 在此答案中,假设您已经能够使用驱动器 API 从 Google 驱动器获取值。请注意这一点。
- 顺便说一句,比如当你想取回
importFormats
的值时,请将export_formats = res.export_formats
和export_formats = res['exportFormats']
修改为import_formats = res.import_formats
和import_formats = res['importFormats']
, 分别.