Scarica file

Una volta completata la generazione dei file di dati strutturati, scarica il file ZIP risultante dalla posizione della risorsa fornita utilizzando media.download.

Ecco come recuperare la posizione del file e scaricare il file 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}.')

Estrai file

Decomprimi il file ZIP scaricato per estrarre i file di dati strutturati generati. Hanno nomi generici che identificano il tipo di file, ad esempio SDF-LineItems.csv.

Se i dati per una risorsa richiesta non possono essere inclusi nel file di dati strutturati generato, il file ZIP includerà anche un file "Ignorato" per quella risorsa, ad esempio SDF-LineItems-Skipped.csv. I file "Ignorati" hanno una struttura a due colonne. La prima colonna identifica la risorsa ignorata e la seconda contiene il messaggio di errore che spiega la sua esclusione.