Issue Creating DemandGenVideoResponsiveAdInfo Instance – Dict vs Protobuf Initialization

63 views
Skip to first unread message

Fausto Esthela Espinoza

unread,
Mar 26, 2025, 5:58:57 AM3/26/25
to Google Ads API and AdWords API Forum

Hi everyone,

I'm currently working with the Google Ads API v18 to create a Demand Gen Video Responsive Ad, and I've run into a confusing issue when trying to initialize the DemandGenVideoResponsiveAdInfo.

When I attempt to initialize the object like this:

DemandGenAdInfoClass = client.get_type("DemandGenVideoResponsiveAdInfo")()
I get the following error:
Message must be initialized with a dict: google.ads.googleads.v18.common.DemandGenVideoResponsiveAdInfo  

This suggests the API expects a dictionary rather than a protobuf instance. However, if I try the alternative:  
DemandGenAdInfoClass = client.get_type("DemandGenVideoResponsiveAdInfo")

and then use:
demand_ad = DemandGenAdInfoClass()
 

So I’m stuck between two approaches — one gives a dict initialization error, and the other says the object is not callable.

Could anyone please clarify the correct way to instantiate and populate DemandGenVideoResponsiveAdInfo in v18?

Share my code.

Any working code example would be greatly appreciated.

Thanks in advance!


def create_video(self, ad_create: GAdCreate):
    try:
        if not ad_create.url.startswith("http"):
            raise ValueError("URL final inválida")
        if not ad_create.video_id:
            raise ValueError("video_id no puede ser nulo o vacío")
        if not ad_create.image_id:
            raise ValueError("El image_id (logo) es obligatorio.")

        video_asset_resource = f"customers/{customer_id}/assets/{ad_create.video_id}"
        logo_asset_resource = f"customers/{customer_id}/assets/{ad_create.image_id}"

        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.ad_group = f"customers/{customer_id}/adGroups/{ad_create.ad_group_id}"
        ad_group_ad.status = (
            client.enums.AdGroupAdStatusEnum.ENABLED
            if ad_create.status.upper() == "ACTIVE"
            else client.enums.AdGroupAdStatusEnum.PAUSED
        )

        ad = ad_group_ad.ad
        ad.final_urls.append(ad_create.url)
        ad.name = f"Video Ad Demand Gen {uuid.uuid4()}"

        # Crear instancia de DemandGenVideoResponsiveAdInfo
        DemandGenAdInfoClass = client.get_type("DemandGenVideoResponsiveAdInfo")
        demand_ad = DemandGenAdInfoClass()
        demand_ad.business_name = "Confía Salud"

        # Video asset
        video_asset = client.get_type("AdVideoAsset")()
        video_asset.asset = video_asset_resource
        demand_ad.videos.append(video_asset)

        # Headlines (min 3)
        for text in [ad_create.headline, ad_create.headline2, ad_create.headline3]:
            if text:
                headline = client.get_type("AdTextAsset")()
                headline.text = text
                demand_ad.headlines.append(headline)

        if len(demand_ad.headlines) < 3:
            raise ValueError("Se requieren al menos 3 titulares.")

        # Descriptions (min 2)
        for text in [ad_create.description, ad_create.description2]:
            if text:
                description = client.get_type("AdTextAsset")()
                description.text = text
                demand_ad.descriptions.append(description)

        if len(demand_ad.descriptions) < 2:
            raise ValueError("Se requieren al menos 2 descripciones.")

        # Logo obligatorio
        logo_asset = client.get_type("AdImageAsset")()
        logo_asset.asset = logo_asset_resource
        demand_ad.logo_images.append(logo_asset)

        # Asignar a la estructura del anuncio
        ad.demand_gen_video_responsive_ad.CopyFrom(demand_ad)

        # Enviar solicitud
        ad_response = ad_group_ad_service.mutate_ad_group_ads(
            customer_id=customer_id,
            operations=[ad_group_ad_operation]
        )

        ad_resource_name = ad_response.results[0].resource_name
        ad_id = ad_resource_name.split("~")[-1]

        api_response = {
            "resource_name": ad_resource_name,
            "ad_id": ad_id
        }

        print("\u2705 Anuncio creado correctamente:")
        print(api_response)
        return api_response

    except GoogleAdsException as ex:
        print(f"❌ Error API al crear el anuncio: {ex}")
        raise
    except Exception as ex:
        print(f"❌ Error general al crear el anuncio: {ex}")
        raise

Google Ads API Forum Advisor

unread,
Mar 26, 2025, 10:56:58 AM3/26/25
to fausto...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for reaching out to the Google Ads API support team. 

I understand you're encountering a "dict: google.ads.googleads.v18.common.DemandGenVideoResponsiveAdInfo" error when creating a Demand Gen Video Responsive Ad.

While the official Google Ads API documentation details the structure of DemandGenVideoResponsiveAdInfo, it lacks a direct, code example for its instantiation.

To help you get started with creating Demand Gen campaigns and ads, please review these resources:

To help us investigate the specific error you are seeing, please provide the complete API logs (request and response logs with request-id and request header) generated on your end.

If you are using a client library and haven't enabled the logging yet, I would request you to enable logging for the specific client library that you are using. You can refer to the guide Python to enable logging at your end. For REST interface requests, you can enable logging via the curl command by using the -i flag.

You can send the details via Reply privately to the author option, or direct private reply to this email.


Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-03-26 14:56:13Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vHCni:ref" (ADR-00296684)



Reply all
Reply to author
Forward
0 new messages