Google Ads / Media Bundle Upload (Python)

214 views
Skip to first unread message

Fabio Szostak

unread,
May 12, 2020, 7:27:15 AM5/12/20
to AdWords API and Google Ads API Forum
Hello,

I`m new here.
I need upload media bundle package to Google Ads,  
I found how to send text ads in Google Ads Examples, but not how to send zip files, no documentation.
In the code below the package upload is done but dont found how to create the ad.
Anybody can help me?
Thanks

ad_group_ad_service = self.g_ads_client.get_service('AdGroupAdService', version='v3')
ad_group_service = self.g_ads_client.get_service('AdGroupService', version='v3')

uploads = []
ad_group_ad_operations = []
messages = []

for resource in mutate_media_files_response.results:
messages.append(
f'Uploaded file with resource name "{resource.resource_name}"'
)
uploads.append(resource.resource_name)

# Create ad group ad.
ad_group_ad_operation = self.g_ads_client.get_type('AdGroupAdOperation', version='v3')
ad_group_ad = ad_group_ad_operation.create
ad_group_ad.ad_group.value = ad_group_service.ad_group_path(
customer_id, ad_group_id)
ad_group_ad.status = self.g_ads_client.get_type('AdGroupAdStatusEnum',
version='v3').PAUSED
# Set expanded display upload ad info
ad_group_ad.ad.display_upload_ad.display_upload_product_type = (
self.g_ads_client.get_type(
'DisplayUploadProductTypeEnum',
version='v3'
).HTML5_UPLOAD_AD
)

# here the problem
# ad_group_ad.ad.display_upload_ad.media_bundle.message = ???????

# one try
#ad_group_ad.ad.display_upload_ad.media_bundle.asset = (
# MediaBundleAsset(mutate_media_files_response)
#)

ad_group_ad_operations.append(ad_group_ad_operation)

Google Ads API Forum Advisor Prod

unread,
May 12, 2020, 10:33:32 AM5/12/20
to fszo...@gmail.com, adwor...@googlegroups.com
Hi Fabio,

Thank you for reaching out. You should start by creating a MediaBundleAsset by following the instructions here (but with type MediaBundleAsset). Once that is done and you have the asset ID, you can use the AdGroupAdService to create a DisplayUploadAd and specify the media_bundle attribute as the asset you created.

Regards,
Mitchell
Google Ads API Team

ref:_00D1U1174p._5004Q1zLTbr:ref

Fabio Szostak

unread,
May 12, 2020, 12:06:36 PM5/12/20
to Google Ads API Forum Advisor Prod, adwor...@googlegroups.com
Hi, thanks for the quick reply...

I am uploading the Media Bundle already, just haven't posted that part of the code. Here is the complete code, uploading the Media Bundle and than trying to create the ad. What am I missing, please?

I've put a comment on where I'm stuck

try:
media_file_operation = self.g_ads_client.get_type(
'MediaFileOperation', version='v3')
media_file = media_file_operation.create
media_file.name.value = 'Ad Media Bundle'
media_file.type = (
self.g_ads_client.get_type(
'MediaTypeEnum',
version='v3'
).MEDIA_BUNDLE
)

# Download the ZIP as bytes from the URL
media_file.media_bundle.data.value = requests.get(bundle).content

media_file_service = self.g_ads_client.get_service(
'MediaFileService', version='v3')

mutate_media_files_response = (
media_file_service.mutate_media_files(
customer_id,
[media_file_operation]
)
)

ad_group_ad_service = self.g_ads_client.get_service('AdGroupAdService', version='v3')
ad_group_service = self.g_ads_client.get_service('AdGroupService', version='v3')

uploads = []
ad_group_ad_operations = []
messages = []

for resource in mutate_media_files_response.results:
messages.append(
f'Uploaded file with resource name "{resource.resource_name}"'
)
uploads.append(resource.resource_name)

# Create ad group ad.
ad_group_ad_operation = self.g_ads_client.get_type('AdGroupAdOperation', version='v3')
ad_group_ad = ad_group_ad_operation.create
ad_group_ad.ad_group.value = ad_group_service.ad_group_path(
customer_id, ad_group_id)
ad_group_ad.status = self.g_ads_client.get_type('AdGroupAdStatusEnum',
version='v3').PAUSED
# Set expanded display upload ad info
ad_group_ad.ad.display_upload_ad.display_upload_product_type = (
self.g_ads_client.get_type(
'DisplayUploadProductTypeEnum',
version='v3'
).HTML5_UPLOAD_AD
)

media_bundle_asset = AdMediaBundleAsset()
media_bundle_asset.asset.value = mutate_media_files_response.results[0].resource_name
# here the problem.
ad_group_ad.ad.display_upload_ad.media_bundle = (media_bundle_asset)


Response error: AttributeError: Assignment not allowed to field \"media_bundle\" in protocol message object.


Fabio Szostak

f s

Google Ads API Forum Advisor Prod

unread,
May 13, 2020, 9:23:28 AM5/13/20
to fszo...@gmail.com, adwor...@googlegroups.com
Hi Fabio,

Could you please share the complete detailed request and response logs for the call via Reply privately to author so I can further investigate the issue? You can find information on enabling logging here (log level = DEBUG).
Message has been deleted

Fabio Szostak

unread,
May 18, 2020, 4:02:04 PM5/18/20
to AdWords API and Google Ads API Forum
Hi Mitchell,

Thanks for your reply.

We enable the logging and the problem was shown, we managed to follow.

Now, we stop in this point, this code is ok?


ad_media_bundle_asset = client.get_type('AdMediaBundleAsset', version='v3')
string_value = client.get_type('StringValue', version='v3')
string_value.value = mutate_media_files_response.results[0].resource_name
ad_media_bundle_asset.asset = string_value # <<===STOP HERE
ad_group_ad.ad.display_upload_ad.media_bundle = ad_media_bundle_asset


Traceback (most recent call last):
File "/app/modules/ads.py", line 168, in mediaUpload
media_bundle_asset.asset = string_value
AttributeError: Assignment not allowed to field "asset" in protocol message object.


Another doubt, which Python version is certified for this API?

Thanks!
Fabio Szostak

Google Ads API Forum Advisor Prod

unread,
May 19, 2020, 11:14:38 AM5/19/20
to fszo...@gmail.com, adwor...@googlegroups.com
Hi Fabio,

It looks like you need to set ad_media_bundle_asset to the specific media bundle asset, not the AdMediaBundleAsset type. This can be done by setting the Asset ID through the AssetService. If you are still having issues, please share the logs via Reply privately to author.

You can find the Python client library requirements here. You need Python 3.7+.
Reply all
Reply to author
Forward
0 new messages