您可以使用 Display & Video 360 API 上傳結構化資料檔案,以程式輔助方式大量建立及更新資源,包括 YouTube 資源。本頁面討論如何使用 API 準備和上傳結構化資料檔。
每個廣告主 ID 每天只能透過 Google Cloud 專案上傳 30 個結構化資料檔案。
準備要上傳的結構化資料檔案
上傳的結構化資料檔案應該是最近修改的版本。下載的結構化資料文件文件類型相同,且來自同一廣告商。請對下載的結構化資料檔案進行以下更新,以準備上傳:
- 新增您想要建立的任何新資源的條目。
- 更新您想要更新的資源的現有條目。
- 移除所有未更新或未新增的項目,以縮減檔案大小、加快處理速度,並避免任何非預期的更新。
上傳檔案前,請先確認下列事項:
- 該檔案是一個
CSV檔案。 - 文件中所有條目均屬於同一父廣告商旗下的資源。
- 檔案中的項目數量未超過 10,000 個。
上傳檔案
使用 advertisers.sdfuploadtasks.upload 方法上傳結構化資料檔案。這項要求會建立 SDF 上傳工作 Operation。這項長時間執行的作業會處理上傳的檔案、根據檔案內容建立及更新資源,並產生結果檔案,列出更新成功和失敗的項目。
以下是如何上傳結構化資料檔案並檢索結果的方法。Operation :
# Import the object used as the media body for the upload request. from apiclient.http import MediaFileUpload # Provide the parent advertiser ID for the resources in the SDF. # The ID value must be a str and not an int. advertiser_id = advertiser-id # Provide the filename and local path to the media file. sdf_filename = sdf-filename sdf_path = sdf-path # Create the request body. body = { 'filename': sdf_filename, 'advertiserId': advertiser_id } # Create the upload object and use a default MIME type if not identified. media = MediaFileUpload(sdf_path) if not media.mimetype(): media = MediaFileUpload(sdf_filename,'application/octet-stream') # Upload the structured data file. upload_response = service.advertisers().sdfuploadtasks().upload( advertiserId=advertiser_id, body=body, media_body=media ).execute() # Print resulting Operation name. print(f'SDF was successfully uploaded. Operation {upload_response["name"]} was ' 'created to process the uploaded file.')