from googleapiclient.discovery import build from google.oauth2 import service_account from googleapiclient.http import MediaFileUpload import pdb pdb.set_trace() import gradio as gr # 来自Google Cloud控制台的JSON凭据文件 credentials_file = "./src/peerless-window-254907-b386b71c0d99.json" api_version = 'v3' # 创建服务对象 credentials = service_account.Credentials.from_service_account_file( credentials_file, scopes=['https://www.googleapis.com/auth/drive']) service = build('drive', api_version, credentials=credentials) # 列出文件 results = service.files().list().execute() files = results.get('files', []) print(files) from googleapiclient.http import MediaIoBaseDownload import io file_id = "1YjON2ObGM826KaaqF-sKM7CO0tAtzWGg" # Get the file's metadata file = service.files().get(fileId=file_id).execute() pdb.set_trace() request = service.files().get_media(fileId="1YjON2ObGM826KaaqF-sKM7CO0tAtzWGg") with open(file['name'], 'wb') as file_obj: downloader = MediaIoBaseDownload(file_obj, request) done = False while not done: status, done = downloader.next_chunk() print(f"Download {int(status.progress() * 100)}%.") print(f"Downloaded: {file['name']}") pdb.set_trace() # print('文件ID:%s' % response.get('id'))