*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

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/adwords-api/0d651b6d-8d7f-4eaa-9407-5fb0d6dbf46an%40googlegroups.com.
  • I... Fausto Esthela Espinoza
    • ... 'Google Ads API Forum Advisor' via Google Ads API and AdWords API Forum

Reply via email to