בסיום הפעולה וחילצתם את שם המשאב מהתגובה שהושלמה, תוכלו להוריד ב-method media.download
את קובץ ה-ZIP שמכיל את מפתחות ה-SDF שנוצרו.
כך משתמשים בספריית לקוח כדי להוריד את הקובץ שנוצר:
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
). הקובץ יהיה במבנה של שתי עמודות, הראשון מכיל את המזהים של המשאבים שלא ניתן היה לכלול, והשני מכיל את הסיבה להחרגה.
יכול להיות שהמערכת מדלגת על המשאבים מסיבות רבות, כולל אי-תמיכה או אי-תמיכה מסוג מסוים. כדי להימנע מדילוג על משאבים, כדאי להשתמש בגרסה העדכנית ביותר של SDF.