googleads/google-ads-python

Issue creating demand gen video responsive ad with Google Ads API - AttributeError and missing required field

yerlan-yesmoldin opened this issue · 2 comments

What is your question?
I'm encountering an issue while trying to create a demand gen video responsive ad using the Google Ads API. I've successfully created a campaign and an ad group, but I'm running into problems when creating the ad itself.

Here's the situation:

  1. When I include the business_name field, I get this error:

    AttributeError: Assignment not allowed to message, map, or repeated field "business_name" in protocol message object.
    
  2. When I remove the business_name field, I get a different error:

    message: "The required field was not present."
    location {
      field_path_elements {
        field_name: "operations"
        index: 0
      }
      field_path_elements {
        field_name: "create"
      }
      field_path_elements {
        field_name: "ad"
      }
      field_path_elements {
        field_name: "demand_gen_video_responsive_ad"
      }
    }
    

I've checked the proto message and included what I believe are all the required fields:

  • headlines
  • long_headlines
  • descriptions
  • videos
  • logo_images
  • breadcrumb1
  • breadcrumb2
  • call_to_actions

Here's a snippet of my code:

def create_ad_group_ad(client, customer_id, ad_group_resource_name):
    """Creates a demand gen ad."""
    ad_group_ad_service = client.get_service("AdGroupAdService")

    ad_group_ad_operation = client.get_type("AdGroupAdOperation")
    ad_group_ad = ad_group_ad_operation.create
    ad_group_ad.status = client.enums.AdGroupAdStatusEnum.ENABLED
    ad_group_ad.ad_group = ad_group_resource_name

    headline_1 = create_ad_text_asset(client, "Headline 1 testing")
    long_headline_1 = create_ad_text_asset(client, "Long Headline 1 testing")
    description_1 = create_ad_text_asset(client, "Desc 1 testing")
    business_name_1 = create_ad_text_asset(client, "Business")
    video_url = create_ad_group_ad_video_asset(client, customer_id)
    video = create_ad_video_asset(client, video_url)

    image_url = create_ad_group_ad_image_asset(client, customer_id)
    image = create_ad_image_asset(client, image_url)

    ad_group_ad.ad.demand_gen_video_responsive_ad.long_headlines.append(
        long_headline_1
    )

    ad_group_ad.ad.demand_gen_video_responsive_ad.descriptions.append(
        description_1
    )
    ad_group_ad.ad.demand_gen_video_responsive_ad.headlines.append(
        headline_1
    )
    ad_group_ad.ad.demand_gen_video_responsive_ad.videos.append(video)
    ad_group_ad.ad.demand_gen_video_responsive_ad.logo_images.append(image)
    ad_group_ad.ad.name = 'test ad name'
    ad_group_ad.ad.final_urls.append("https://www.example.com")
    ad_group_ad.ad.demand_gen_video_responsive_ad.breadcrumb1 = '123'
    ad_group_ad.ad.demand_gen_video_responsive_ad.breadcrumb2 = '123'
    ad_group_ad.ad.demand_gen_video_responsive_ad.call_to_actions.append(
        create_ad_call_to_action_asset(client, create_ad_group_ad_call_to_action(client, customer_id))
    )
    # ad_group_ad.ad.demand_gen_video_responsive_ad.business_name = business_name_1

    # Add the ad
    ad_group_ad_response = ad_group_ad_service.mutate_ad_group_ads(
        customer_id=customer_id, operations=[ad_group_ad_operation]
    )

    for result in ad_group_ad_response.results:
        print(f"Created demand gen ad with resource name {result.resource_name}.")

Questions:

  1. Am I missing any required fields for creating a demand gen video responsive ad?
  2. How should I properly set the business_name field to avoid the AttributeError?
  3. Are there any common pitfalls or gotchas when creating this type of ad that I should be aware of?

Any guidance or insights would be greatly appreciated. Thank you!

Using google-ads==25.0.0

Resolved:
You should set
use_proto_plus: True