After Structured Data Files finish generating successfully, download the
resulting ZIP
file from the provided resource location using
media.download
.
Here's how to retrieve the file location and download the ZIP
file:
# 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}.')
Extract files
Decompress the downloaded ZIP
file to extract the generated Structured Data
Files. They have generic names identifying their file type, such as
SDF-LineItems.csv
.
If data for a requested resource couldn't be included in the generated
Structured Data file, the ZIP
file will also include a "Skipped" file for that
resource, such as SDF-LineItems-Skipped.csv
. "Skipped" files have a two column
structure. The first column identifies the skipped resource and the second
column contains the error message explaining their exclusion.