Add More Youtube Videos on Existing AdGroupAd

34 views
Skip to first unread message

Dev

unread,
Apr 3, 2024, 7:50:40 PM4/3/24
to Google Ads API and AdWords API Forum
Hello,

I have a problem when mutating AdGroupAd. I want to add more video and image to existing  AdGroup. This is my code:

```python
ga_service = self.__client.get_service("GoogleAdsService")
        query = f"""
                SELECT
                  ad_group_ad.resource_name    
                FROM ad_group_ad
                WHERE ad_group.resource_name = '<redacted>'"""

        self._get_logger().info(f"AdGroupAd -> query: {query}")

        response = ga_service.search_stream(customer_id=self.__customer_id, query=query)

        self._get_logger().info(f"AdGroupAd -> response: {response}")

        initial_ad_group_ad = None

        for batch in response:
            for row in batch.results:
                self._get_logger().info(f"AdGroupAd: {row}")
                initial_ad_group_ad = row.ad_group_ad

        if initial_ad_group_ad is None:
            raise Exception(f"Ad Group Ad not found! {ad_group_resource_name}")

        ad_group_ad_operation = self.__client.get_type('AdGroupAdOperation')
        updated_ad_group_ad = ad_group_ad_operation.update
        updated_ad_group_ad.resource_name = initial_ad_group_ad.resource_name

        updated_ad_group_ad.ad.app_ad.images.extend(
            [
                self.__ad_image_adset_from_media_resource_name(
                    media_resource_name='<redacted>'
                )
            ]
        )

        field_mask = protobuf_helpers.field_mask(
            None, updated_ad_group_ad._pb
        )

        self.__client.copy_from(ad_group_ad_operation.update_mask, field_mask)

        ad_group_ad_service = self.__client.get_service('AdGroupAdService')

        response = ad_group_ad_service.mutate_ad_group_ads(
            customer_id=self.__customer_id, operations=[ad_group_ad_operation],
        )

        resource_name = response.results[0].resource_name

        self._get_logger().info(f"AdGroupAd updated! resource_name:{resource_name}")
```

But I got this error instead (see attached screenshots)

Am I using wrong approach? Please inform me the recommended way on how to add more images or videos to existing AdGroup. Thanks guys!
Screen Shot 2024-04-03 at 22.42.37.png
Screen Shot 2024-04-03 at 22.43.03.png

Google Ads API Forum Advisor

unread,
Apr 4, 2024, 4:34:38 PM4/4/24
to d...@play3.gg, adwor...@googlegroups.com
Hi,

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

It appears that you are using the AdGroupAdService to update the ad. Please note that using this service, Ad is immutable and this is the reason that you are getting errors when updating the said ad. With this, I would recommend that you use the AdService instead and see this AdOperation.

Hope this helps.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02tOqm2:ref" (ADR-00229863)

Thanks,
 
Google Logo Google Ads API Team


Reply all
Reply to author
Forward
0 new messages