从python读取G驱动器中的文件



我有一个GCP项目,有一个Jupiter笔记本,可以从G Drive读取文件。

def search_file(request = None):
try:
service = build('drive', 'v3', credentials=creds)
# Call the Drive v3 API
results = service.files().list(
pageSize=1, fields="nextPageToken, files(id, name)").execute()
items = results.get('files', [])
if not items:
print('No files found.')
return
print('Files:')
for item in items:
print(u'{0} ({1})'.format(item['name'], item['id']))
except HttpError as error:
print(f'An error occurred: {error}')

我正在使用谷歌的快速启动从G驱动器检索文件。身份验证和所有操作都很好,目标驱动器上只有一个文件。但当我执行这个search_file方法时,我会收到No Files found.消息。我正在尝试读取一个csv文件,该文件位于G驱动器中。我错过了什么或有其他选择吗?

您可以尝试以以下格式运行查询吗?

shared_drive_id = "" # you need to specify specific id of drive folder provided in url of that folder such as https://drive.google.com/drive/folders/<shared_drive_id>

query_file = "mimeType='application/vnd.google-apps.document' and trashed=false"
search_file = drive_service.files().list(q=query_file,
fields='files(id)',
driveId=shared_drive_id,
supportsAllDrives=True,
includeItemsFromAllDrives=True,
corpora='drive').execute()
files = search_file.get('files', [])

相关内容

  • 没有找到相关文章

最新更新