Updating ImageAd's image via the GoogleAdsAPI.

125 views
Skip to first unread message

本舘勤

unread,
Feb 6, 2020, 3:21:16 AM2/6/20
to AdWords API and Google Ads API Forum
Hi.

We tried updating ImageAd's image via the GoogleAdsAPI with the following code:

```
$adGroupAd = new AdGroupAd([
    'resource_name' => ResourceNames::forAdGroupAd(GOOGLE_ADS_CUSTOMER_ID, $paramAd->getAdGroup()->getId()->getValue(), $paramAd->getAdGroupAd()->getAd()->getId()->getValue()),
    'ad' => new Ad([
        'image_ad' => new ImageAdInfo([
            'data' => new BytesValue(['value' => file_get_contents($pathTgt)]),
        ])
    ]),
]);

$operation = new AdGroupAdOperation();
$operation->setUpdate($adGroupAd);
$operation->setUpdateMask(FieldMasks::allSetFieldsOf($adGroupAd));
$operations[] = $operation;

$adGroupAdService->mutateAdGroupAds(GOOGLE_ADS_CUSTOMER_ID, $operations);
```

Howerver, it occurred the error such as:

```
Field 'ad.app_ad' cannot be modified by 'UPDATE' operation.
Field 'ad.app_engagement_ad' cannot be modified by 'UPDATE' operation.
Field 'ad.call_only_ad' cannot be modified by 'UPDATE' operation.
Field 'ad.device_preference' cannot be modified by 'UPDATE' operation.
Field 'ad.display_upload_ad' cannot be modified by 'UPDATE' operation.
Field 'ad.display_url' cannot be modified by 'UPDATE' operation.
Field 'ad.expanded_dynamic_search_ad' cannot be modified by 'UPDATE' operation.
Field 'ad.expanded_text_ad' cannot be modified by 'UPDATE' operation.
Field 'ad.final_app_urls' cannot be modified by 'UPDATE' operation.
Field 'ad.final_mobile_urls' cannot be modified by 'UPDATE' operation.
Field 'ad.final_url_suffix' cannot be modified by 'UPDATE' operation.
Field 'ad.final_urls' cannot be modified by 'UPDATE' operation.
Field 'ad.gmail_ad' cannot be modified by 'UPDATE' operation.
Field 'ad.hotel_ad' cannot be modified by 'UPDATE' operation.
Field 'ad.image_ad.ad_id_to_copy_image_from' cannot be modified by 'UPDATE' operation.
Field 'ad.image_ad.data' cannot be modified by 'UPDATE' operation.
```

So, I have some questions.

1) How do we update the ImageAd's image via the GoogleAdsAPI?
2) If we cannot, we have to update the ImageAd's image with the following method?
   a) Create the new ImageAd.
   b) Remove the old ImageAd.

Best Regards.

Google Ads API Forum Advisor Prod

unread,
Feb 6, 2020, 3:30:43 PM2/6/20
to moto...@simnet.co.jp, adwor...@googlegroups.com

Hello,

Thank you for writing to us. With regards to your concern, it is not possible to mutate ad group ads using AdGroupAdService. You will need to use AdService  for updating existing ads that were created using AdGroupAdService. Please modify your request to update the image ad using AdService and let me know if you still have any issues.

Regards,
Nikisha Patel, Google Ads API Team



ref:_00D1U1174p._5001UV05Rt:ref

本舘勤

unread,
Feb 6, 2020, 8:34:23 PM2/6/20
to AdWords API and Google Ads API Forum
Thank you for your answer.

According to your answer, I tried updating the image with AdSerivce.
The code I made is below :

====================
$newImageAd = new ImageAdInfo();
$newImageAd->setData(new BytesValue(['value' => file_get_contents($pathTgt)]));

$updatedAd = new Ad([
    'resource_name' => AdServiceClient::adName(GOOGLE_ADS_CUSTOMER_ID, $adId),
    'image_ad'      => $newImageAd,
]);

$operation = new AdOperation();
$operation->setUpdate($updatedAd);
$operation->setUpdateMask(FieldMasks::allSetFieldsOf($updatedAd));
$operations[] = $operation;

$adService->mutateAds(GOOGLE_ADS_CUSTOMER_ID, $operations);
====================

However, the following error was occurred:

====================
Field 'image_ad.ad_id_to_copy_image_from' cannot be modified by 'UPDATE' operation.
Field 'image_ad.data' cannot be modified by 'UPDATE' operation.
Field 'image_ad.media_file' cannot be modified by 'UPDATE' operation.
====================

Can't we update the image of the ImageAd ?
Or, are there any walk-around?

Best Regards.

2020年2月7日金曜日 5時30分43秒 UTC+9 adsapiforumadvisor:

Google Ads API Forum Advisor Prod

unread,
Feb 7, 2020, 11:44:43 AM2/7/20
to moto...@simnet.co.jp, adwor...@googlegroups.com

Hello,

With regards to your concern related to updating assets (image or videos) of the ads, it is currently not possible to update video/image assets via API. However, if you want to remove the video/image assets associated with an ad, you can use the AssetService.mutate() method by using the 'REMOVE' operator and by specifying the assetId in the request using AdWords API. With Google Ads API Beta, it is only possible to create Assets via API. Remove operation is not yet supported. A feature request regarding your concern is already raised internally within our team. Please keep an eye on our blog for more updates related to this request. Please feel free to reach out if you have any additional API related concerns.



Regards,
Nikisha Patel, Google Ads API Team



ref:_00D1U1174p._5001UV05Rt:ref
Reply all
Reply to author
Forward
0 new messages