Tải SDF xuống

Sau khi thao tác xong và trích xuất tên tài nguyên từ phản hồi thao tác hoàn tất, bạn có thể tải tệp zip chứa SDF đã tạo xuống bằng phương thức media.download.

Dưới đây là ví dụ về cách sử dụng thư viện ứng dụng để tải tệp kết quả xuống:

Java

// Extract download file resource name to use in download request
String downloadResourceName = operationResponse.getResponse()
    .get("resourceName").toString();

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

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

// Download file
downloadRequest.executeMediaAndDownloadTo(outStream);

System.out.printf("File downloaded to %s\n", outputFile);

Python

# Extract download file resource name to use in download request
resourceName = operation["response"]["resourceName"]

# Configure the Media.download request
downloadRequest = service.media().download_media(resourceName=resourceName)

# Create output stream for downloaded file
outStream = io.FileIO(output-file, mode='wb')

# Make downloader object
downloader = googleHttp.MediaIoBaseDownload(outStream, downloadRequest)

# Download media file in chunks until finished
download_finished = False
while download_finished is False:
  _, download_finished = downloader.next_chunk()

print("File downloaded to %s" % output-file)

1.199

// Get client and set defer so it doesn't immediately return.
$client = $this->service->getClient();
$client->setDefer(true);

// Build media download request.
$request = $this->service->media->download(
    $operation->getResponse()['resourceName'],
    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(output-file, $responseBody);
$client->setDefer(false);

printf('File saved to: %s\n', output-file);

Sau khi tải tệp xuống và giải nén, bạn có thể sử dụng các tệp dữ liệu có cấu trúc đã tạo. Các tệp được tạo sẽ có tên chung để xác định loại tệp SDF (ví dụ: SDF-LineItems.csv).

Tệp đã bỏ qua

Nếu không thể đưa dữ liệu cho tài nguyên được yêu cầu vào tệp dữ liệu có cấu trúc tương ứng, tệp zip được tải xuống có thể bao gồm tệp "Đã bỏ qua" (ví dụ: SDF-LineItems-Skipped.csv). Tệp này sẽ có cấu trúc hai cột, cột thứ nhất chứa mã nhận dạng của các tài nguyên không thể đưa vào và cột thứ hai chứa lý do loại trừ tài nguyên.

Tài nguyên có thể bị bỏ qua vì nhiều lý do, bao gồm cả việc tài nguyên ở trạng thái không được hỗ trợ hoặc thuộc loại không được hỗ trợ. Tránh bỏ qua tài nguyên bằng cách sử dụng phiên bản SDF mới nhất.