结构化数据文件成功生成后,使用 media.download 从提供的资源位置下载生成的 ZIP 文件。
以下是检索文件位置并下载 ZIP 文件的方法:
# Import the object used for media download. from googleapiclient import http as googleHttp # Provide the name of the successfully completed sdfdownloadtask operation. operation_name = operation-name # Provide the path for the output file. output_path = output-path # Retrieve the completed operation. operation = service.sdfdownloadtasks().operations().get(operation_name ).execute() # Retrieve the file location from the operation. file_location = operation["response"]["resourceName"] # Configure the media.download request. download_request = service.media().download_media(resourceName=file_location) # Create output stream for downloaded file. out_stream = io.FileIO(output_path, mode='wb') # Build downloader object. downloader = googleHttp.MediaIoBaseDownload(out_stream, download_request) # Download file in chunks until finished. download_finished = False while download_finished is False: _, download_finished = downloader.next_chunk() print(f'File downloaded at {output_path}.')
提取文件
解压缩下载的 ZIP 文件,以提取生成的结构化数据文件。它们具有用于标识文件类型的通用名称,例如 SDF-LineItems.csv。
如果无法在生成的结构化数据文件中包含所请求资源的数据,ZIP 文件还会包含相应资源的“已跳过”文件,例如 SDF-LineItems-Skipped.csv。“跳过”的文件具有两列结构。第一列用于标识被跳过的资源,第二列包含说明排除原因的错误消息。