与由其他类型的订单项投放的广告素材不同,由
需求开发广告投放的广告素材是在 AdGroupAd 资源
本身中构建的。分配给广告以构建这些广告素材的图片和视频素材资源在 Display & Video 360 API 中由 AdAsset 资源表示。
在创建 AdGroupAd 资源之前,请先创建广告将使用的相关
AdAsset 资源(如果这些资源尚不存在)。如果这些资源之前是使用界面或 API 创建的,您可以检索
现有素材资源,方法是使用 advertisers.adAssets 服务的 get
和 list 方法。
图片和视频 AdAsset 资源是使用不同的
方法创建的:
- 图片素材资源必须使用
advertisers.adAssets.upload方法上传到 Display & Video 360。 - 视频素材资源必须使用 YouTube 视频 ID 进行关联,并使用
advertisers.adAssets.create方法创建。
adAssetId 资源的 AdAsset 用于
将素材资源与需求开发广告相关联。
上传图片素材资源
上传图片文件以创建 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.")