Tworzenie komponentów reklamy

W przeciwieństwie do kreacji wyświetlanych przez inne typy elementów zamówienia kreacje wyświetlane przez reklamy generujące popyt są tworzone w samych zasobach AdGroupAd. Zasoby graficzne i wideo przypisane do reklam w celu tworzenia tych kreacji są reprezentowane w Display & Video 360 API przez zasoby AdAsset.

Zanim utworzysz zasób AdGroupAd, utwórz odpowiednie zasoby AdAsset, których reklama będzie używać, jeśli jeszcze nie istnieją. Jeśli zostały wcześniej utworzone za pomocą interfejsu lub interfejsu API, możesz pobrać istniejące komponenty za pomocą usług advertisers.adAssets get i list.

Zasoby z obrazem i filmem AdAsset są tworzone różnymi metodami:

Do powiązania komponentu z reklamą generującą popyt używany jest adAssetId zasobu AdAsset.

Przesyłanie komponentów z obrazem

Prześlij pliki obrazów, aby utworzyć AD_ASSET_TYPE_IMAGE komponenty, które mogą być używane jako banery towarzyszące, logo i obrazy marketingowe.

Aby przesłać komponent z obrazem i utworzyć zasób 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.")

Tworzenie komponentów YouTube

Podaj identyfikatory filmów na YouTube, aby utworzyć komponenty AD_ASSET_TYPE_YOUTUBE_VIDEO, których można używać w reklamach wideo generujących popyt.

Aby utworzyć komponent wideo w YouTube i utworzyć zasób 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.")