파일 다운로드

구조화된 데이터 파일이 성공적으로 생성되면 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열 구조입니다. 첫 번째 열은 건너뛴 리소스를 식별하고 두 번째 열에는 제외를 설명하는 오류 메시지가 포함됩니다.