作業順利完成並擷取資源後
完成作業回應的名稱後,即可下載 ZIP 檔案
檔案,其中含有您產生的結構化資料檔案,請使用 media.download
方法。
以下範例說明如何使用用戶端程式庫下載產生的檔案:
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);
檔案下載並解壓縮後,產生的結構化資料檔案
就能使用。產生的檔案將會使用一般名稱
識別 SDF 檔案類型 (例如:SDF-LineItems.csv
)。
略過的檔案
如果要求的資源中不包含要求資源的資料
結構化資料檔案,下載的 ZIP 檔案可能包含「已略過」檔案
(範例:SDF-LineItems-Skipped.csv
)。這個檔案會有一個資料欄
第一個包含無法擷取的資源 ID
第二個則包含排除原因
系統略過資源的原因很多,包括位於不支援的資源 狀態或不受支援的類型避免使用 最新版本的 SDF。