Không giống như những mẫu quảng cáo được phân phát bởi các loại mục hàng khác, mẫu quảng cáo được phân phát bởi
quảng cáo Tạo nhu cầu được tạo trong chính tài nguyên AdGroupAd. Các thành phần hình ảnh và video được chỉ định cho quảng cáo để tạo các mẫu quảng cáo này được biểu thị trong API Display & Video 360 bằng AdAsset tài nguyên.
Trước khi tạo tài nguyên AdGroupAd, hãy tạo các tài nguyên
AdAsset có liên quan mà quảng cáo sẽ sử dụng nếu chúng chưa tồn tại. Nếu trước đây bạn đã tạo các tài nguyên này bằng giao diện người dùng hoặc API, thì bạn có thể truy xuất
các thành phần hiện có bằng dịch vụ advertisers.adAssets get
và các phương thức list.
Tài nguyên AdAsset hình ảnh và video được tạo bằng các phương thức khác nhau:
- Bạn phải tải các thành phần hình ảnh lên Display & Video 360 bằng phương thức
advertisers.adAssets.upload. - Bạn phải liên kết các thành phần video bằng mã video trên YouTube và tạo bằng phương thức
advertisers.adAssets.create.
adAssetId của tài nguyên AdAsset được dùng
để liên kết một thành phần với quảng cáo Tạo nhu cầu.
Tải thành phần hình ảnh lên
Tải tệp hình ảnh lên để tạo thành phần AD_ASSET_TYPE_IMAGE có thể dùng làm biểu ngữ đồng hành, biểu trưng và hình ảnh tiếp thị.
Sau đây là cách tải thành phần hình ảnh lên để tạo AdAsset
tài nguyên:
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.")
Tạo thành phần trên YouTube
Cung cấp mã video trên YouTube để tạo thành phần AD_ASSET_TYPE_YOUTUBE_VIDEO có thể dùng trong quảng cáo dạng video Tạo nhu cầu.
Sau đây là cách tạo thành phần video trên YouTube để tạo tài nguyên
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.")