構造化データファイルの生成が正常に完了したら、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 など)も含まれます。「スキップ」されたファイルは 2 列の構造になっています。最初の列はスキップされたリソースを示し、2 番目の列には除外を説明するエラー メッセージが含まれています。