Sau khi thao tác của bạn hoàn tất và bạn đã 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 các SDF đã tạo xuống bằng phương thức media.download
.
Sau đâ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)
PHP
// 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 sẽ thấy 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 một tài nguyên được yêu cầu vào tệp dữ liệu có cấu trúc tương ứng, thì tệp zip đã 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 đầu tiên 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ừ các tài nguyên đó.
Tài nguyên có thể bị bỏ qua vì nhiều lý do, bao gồm cả việc ở trạng thái không được hỗ trợ hoặc thuộc loại không được hỗ trợ. Tránh việc bỏ qua tài nguyên bằng cách sử dụng phiên bản SDF mới nhất.