파일 다운로드

생성된 구조화된 데이터 파일 (SDF)은 ZIP 파일에 저장됩니다. media.download를 사용하여 성공한 Operationresponse.resourceName 필드에 있는 값을 사용하여 이 파일을 다운로드합니다.

SDF ZIP 파일을 다운로드하는 방법은 다음과 같습니다.

자바

// Provide the name of the finished sdfdownloadtask operation.
String operationName = operation-name;

// Provide the path for the output file.
String outputFile = output-file;

// Retrieve the resource location from the finished operation.
Operation operation = service.sdfdownloadtasks().operations().get(operationName).execute();
String fileLocation = operation.getResponse().get("resourceName").toString();

// Configure the Media.download request.
Media.Download downloadRequest = service.media().download(fileLocation);

// Create output stream for downloaded file.
FileOutputStream outStream = new FileOutputStream(outputFile);

// Download file.
downloadRequest.executeMediaAndDownloadTo(outStream);
System.out.printf("File downloaded at %s", outputFile);

Python

# 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(name=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}.")

PHP

// Provide the name of the finished sdfdownloadtask operation.
$operationName = operation-name;

// Provide the path for the output file.
$outputFile = output-file;

try {
    // Call the API, retrieving the SDF Download Task.
    $operation = $this->service->sdfdownloadtasks_operations->get(
        $operationName
    );

    $fileLocation = $operation->getResponse()['resourceName'];

    $client = $this->service->getClient();
    $client->setDefer(true);

    $request = $this->service->media->download(
        $fileLocation,
        array('alt' => 'media')
    );

    // Call the API, getting the generated SDF.
    $response = $client->execute($request);
    $responseBody = $response->getBody();

    // Writes the downloaded file. If the file already exists, it is
    // overwritten.
    file_put_contents($outputFile, $responseBody);
    $client->setDefer(false);

} catch (\Exception $e) {
    $this->renderError($e);
    return;
}

printf('<p>File downloaded at %s</p>', $outputFile);

파일 추출

ZIP 파일에서 생성된 SDF를 추출합니다. SDF는 유형을 식별하는 일반 파일 이름을 사용합니다. 광고 항목 SDF의 이름은 SDF-LineItems.csv입니다.

ZIP 파일에는 각 파일 형식에 대해 '건너뛴' 파일이 포함될 수 있습니다. '건너뛴' 파일은 SDF에 포함되지 않은 리소스를 식별합니다. -Skipped 접미사로 이름이 지정됩니다. 이러한 파일은 2열 구조입니다. 첫 번째 열은 건너뛴 리소스를 식별합니다. 두 번째 열에는 제외 이유가 설명되어 있습니다.