code : in attachment
error:
Uploaded file: customers/customer_id/assets/asset_id
Traceback (most recent call last):
File "/home/projects/tirth.com/Podcast
Project/podcast/podcastapp/view/test.py",
line 61, in <module>
main(googleads_client, "customer_id")
File "/home/projects/tirth.com/Podcast
Project/podcast/podcastapp/view/test.py",
line 40, in main
ad_group_ad.ad.image_asset = asset_resource_name
File "/home/tirth/.local/lib/python3.8/site-packages/proto/message.py",
line 772, in __setattr__
raise AttributeError(
AttributeError: Unknown field for Ad: image_asset
On Tuesday, 18 July 2023 at 13:36:47 UTC+5:30 Google Ads API Forum Advisor
wrote:
> Hi,
>
> Thanks for getting back to us.
>
> In order for us to investigate further, can you share with us the *whole
> Google Ads UI screenshot (without cropping) *of the data in the Google
> Ads UI you are trying to set via API? This is so we can check on our end as
> well and provide more appropriate answers accordingly.
>
> Can you also provide more context when you mentioned it is not working? If
> you are encountering API errors on your end, can you provide us with the
> complete API logs (*request* and *response* with *request-id *and *request
> header)* generated on your end when you encountered the issue you
> mentioned? You can provide it via the Reply privately to author option. If
> this option is not available, then send it instead on this email address
> [email protected] <https://groups.google.com/>.
>
> For the client libraries, logging can be enabled by navigating to the
> Client libraries > Your client library (ex Java) > Logging documentation,
> which you can access from this *link *(
> *https://developers.google.com/google-ads/api/docs/client-libs*
> <https://developers.google.com/google-ads/api/docs/client-libs>).
>
> Reference links included in this email:
>
> - request:
>
> *https://developers.google.com/google-ads/api/docs/concepts/field-service?hl=en#request*
>
>
> <https://developers.google.com/google-ads/api/docs/concepts/field-service?hl=en#request>
>
> - response:
>
> *https://developers.google.com/google-ads/api/docs/concepts/field-service?hl=en#response*
>
>
> <https://developers.google.com/google-ads/api/docs/concepts/field-service?hl=en#response>
>
> - request-id:
>
> *https://developers.google.com/google-ads/api/docs/concepts/call-structure?hl=en#request-id*
>
>
> <https://developers.google.com/google-ads/api/docs/concepts/call-structure?hl=en#request-id>
>
> - request header -
>
> *https://developers.google.com/google-ads/api/docs/concepts/call-structure#request_headers*
>
>
> <https://developers.google.com/google-ads/api/docs/concepts/call-structure#request_headers>
>
>
>
> This message is in relation to case "ref:_00D1U1174p._5004Q2n8R6U:ref"
>
> Thanks,
>
> [image: Google Logo] Google Ads API Team
>
>
>
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 on the web visit
https://groups.google.com/d/msgid/adwords-api/b46b01c2-ef1d-467e-bdab-24959c797c21n%40googlegroups.com.
import argparse
import sys
import requests
from google.ads.googleads.client import GoogleAdsClient
from google.ads.googleads.errors import GoogleAdsException
def main(client, customer_id):
"""Main method, to run this code example as a standalone application."""
# Download image from URL
with open("1500x1500.png", "rb") as file1:
image_content = file1.read()
asset_service = client.get_service("AssetService")
asset_operation = client.get_type("AssetOperation")
asset = asset_operation.create
asset.type_ = client.enums.AssetTypeEnum.IMAGE
asset.image_asset.data = image_content
asset.image_asset.mime_type = client.enums.MimeTypeEnum.IMAGE_JPEG
# asset.image_asset.full_size.url = image_content
asset.name = "Marketing Image"
# Upload the asset
mutate_asset_response = asset_service.mutate_assets(
customer_id=customer_id, operations=[asset_operation]
)
asset_resource_name = mutate_asset_response.results[0].resource_name
print(f"Uploaded file: {asset_resource_name}")
# Create ad group ad using the uploaded asset
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 = client.get_service("AdGroupService").ad_group_path(
customer_id, "asset_id"
)
ad_group_ad.ad = client.get_type("Ad")
ad_group_ad.ad.image_asset = asset_resource_name
# Optional: Set other ad properties
ad_group_ad.ad.final_urls = ["https://example.com"]
# Create the ad group ad
mutate_ad_group_ad_response = ad_group_ad_service.mutate_ad_group_ads(
customer_id=customer_id, operations=[ad_group_ad_operation]
)
print(f"Created ad group ad: {mutate_ad_group_ad_response.results[0].resource_name}")
if __name__ == "__main__":
# GoogleAdsClient will read the google-ads.yaml configuration file in the
# home directory if none is specified.
googleads_client = GoogleAdsClient.load_from_storage(
version="v14"
)
try:
main(googleads_client, "customer_id")
except GoogleAdsException as ex:
print(
f'Request with ID "{ex.request_id}" failed with status '
f'"{ex.error.code().name}" and includes the following errors:'
)
for error in ex.failure.errors:
print(f'\tError with message "{error.message}".')
if error.location:
for field_path_element in error.location.field_path_elements:
print(f"\t\tOn field: {field_path_element.field_name}")
sys.exit(1)