googleads / google-ads-python

Google Ads API Client Library for Python
Apache License 2.0
526 stars 480 forks source link

Unable to clear portrait_marketing_images under discovery_multi_asset_ad #861

Closed celeray closed 6 months ago

celeray commented 6 months ago

Unable to clear portrait_marketing_images under discovery_multi_asset_ad,running the library version 24.0.0: I have tried portrait_marketing_images =[] or portrait_marketing_images =None, but it still exists. What is the specific implementation code for clearing portrait_marketing_images?

def update_image_ad_portrait():
    ad_service = client.get_service("AdService")
    ad_operation = client.get_type("AdOperation")
    ad = ad_operation.update
    ad.resource_name = 'xxxxxx'
    image_ad = ad.discovery_multi_asset_ad

    image_ad.portrait_marketing_images = []
    client.copy_from(
        ad_operation.update_mask,
        protobuf_helpers.field_mask(None, ad._pb),
    )
    try:
        ad_service.mutate_ads(
            customer_id=str(xxxxx), operations=[ad_operation]
        )
        logger.info("update image portrait success")
    except GoogleAdsException as ex:
        raise ex
BenRKarl commented 6 months ago

@celeray you likely need to manually add portrait_marketing_images to the field mask to communicate to the API that you're mutating the field to its default value.

See the last section of this page.