與其他類型委刊項放送的廣告素材不同,需求開發廣告放送的廣告素材是在AdGroupAd資源中建構。指派給廣告以建構這些廣告素材的圖片和影片素材資源,在 Display & Video 360 API 中會以 AdAsset 資源表示。
建立 AdGroupAd 資源前,請先建立廣告會使用的相關 AdAsset 資源 (如果尚未建立)。如果先前是使用 UI 或 API 建立,您可以透過 advertisers.adAssets 服務 get 和 list 方法擷取現有資產。
圖片和影片 AdAsset 資源的建立方式如下:
- 圖片素材資源必須使用
advertisers.adAssets.upload方法上傳至 Display & Video 360。 - 影片資產必須使用 YouTube 影片 ID 建立關聯,並透過
advertisers.adAssets.create方法建立。
adAssetId AdAsset 資源的 adAssetId 會用於將素材資源與需求開發廣告建立關聯。
上傳圖片素材資源
上傳圖片檔案,建立可做為隨播橫幅、標誌和行銷圖片的 AD_ASSET_TYPE_IMAGE 素材資源。
如要上傳圖片素材資源來建立 AdAsset 資源,請按照下列步驟操作:
Python
# Import the object used as the media body for the upload request. from apiclient.http import MediaFileUpload # Provide the parent advertiser ID to upload the media file under. advertiser_id = advertiser-id # Provide the filename and local path to the media file. asset_filename = asset-filename asset_path = asset-path # Create the request body. body = {"filename": asset_filename, "adAssetType": "AD_ASSET_TYPE_IMAGE"} # Create the upload object and use a default MIME type if not identified. media = MediaFileUpload(asset_path) if not media.mimetype(): media = MediaFileUpload(asset_path, "application/octet-stream") # Upload the asset. upload_response = ( service.advertisers() .adAssets() .upload(advertiserId=advertiser_id, body=body, media_body=media) .execute() ) # Display the new ad asset. print(f"Ad asset {upload_response['adAsset']['name']} was created.")
建立 YouTube 素材資源
提供 YouTube 影片 ID,即可建立AD_ASSET_TYPE_YOUTUBE_VIDEO素材資源,用於需求開發影片廣告。
以下說明如何建立 YouTube 影片素材資源,以建立 AdAsset 資源:
Python
# Provide the ID of the parent advertiser. advertiser_id = advertiser-id # Provide the ID of the parent insertion order. youtube_video_id = youtube-video-id # Create a line item object with example values. ad_asset_create_body = { "adAsset": { "adAssetType": "AD_ASSET_TYPE_YOUTUBE_VIDEO", "youtubeVideoAsset": {"youtubeVideoId": youtube_video_id}, } } # Build and execute request. response = ( service.advertisers() .adAssets() .create(advertiserId=advertiser_id, body=ad_asset_create_body) .execute() ) # Display the new ad asset. print(f"Ad asset {response['name']} was created.")