ดาวน์โหลด SDF

เมื่อการดำเนินการเสร็จสิ้นและคุณได้ดึงข้อมูลชื่อทรัพยากรจากการตอบกลับการดำเนินการที่เสร็จสมบูรณ์แล้ว คุณก็พร้อมที่จะดาวน์โหลดไฟล์ ZIP ที่มี SDF ที่สร้างขึ้นโดยใช้เมธอด 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) ไฟล์นี้จะมีโครงสร้าง 2 คอลัมน์ โดยไฟล์แรกจะมีรหัสของทรัพยากรที่ไม่ได้รวมไว้และรายการที่ 2 มีเหตุผลของการยกเว้น

ระบบอาจข้ามทรัพยากรด้วยเหตุผลหลายประการรวมถึงอยู่ในสถานะที่ไม่รองรับหรือเป็นประเภทที่ไม่รองรับ หลีกเลี่ยงการข้ามทรัพยากรโดยใช้ SDF เวอร์ชันล่าสุด