How to add AppAdInfo using python?

64 views
Skip to first unread message

go csx

unread,
Dec 26, 2019, 5:33:45 AM12/26/19
to AdWords API and Google Ads API Forum
import datetime
import sys
import time
# import uuid
import uuid

import google
from google.ads.google_ads import client
from google.ads.google_ads.v2.proto.common.ad_asset_pb2 import AdTextAsset
from google.ads.google_ads.v2.proto.common.ad_type_infos_pb2 import AppAdInfo


class GoogleAds:
    def add_ad(self, client, customer_id, ad_group_id):
        ad_group_ad_service = client.get_service('AdGroupAdService', version='v2')
        ad_group_service = client.get_service('AdGroupService', version='v2')

        # Create ad group ad.
        ad_group_ad_operation = client.get_type('AdGroupAdOperation', version='v2')
        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 = client.get_type('AdGroupAdStatusEnum',
                                             version='v2').PAUSED

        #Set expanded text ad info
        #final_url = ad_group_ad.ad.final_urls.add()
        #final_url.value = 'http://www.example.com'
        #ad_group_ad.ad.expanded_text_ad.description.value = 'Buy your tickets now!'
        #ad_group_ad.ad.expanded_text_ad.headline_part1.value = (
         #    'Cruise to Mars %s' % str(uuid.uuid4())[:15])
        #ad_group_ad.ad.expanded_text_ad.headline_part2.value = (
         #    'Best space cruise line')
        #ad_group_ad.ad.expanded_text_ad.path1.value = 'all-inclusive'
        #ad_group_ad.ad.expanded_text_ad.path2.value = 'deals'

 
      # ========== STUCK HERE ==========
        ad_info1 = AdTextAsset()
        ad_info1.text.value = "test_test1"
        ad_info2 = AdTextAsset()
        ad_info2.text.value = "test_test2"
        app_ad = AppAdInfo()
        app_ad.mandatory_ad_text.text.value = "test_text"




        try:
            ad_group_ad_response = ad_group_ad_service.mutate_ad_group_ads(
                customer_id, [ad_group_ad_operation])
        except google.ads.google_ads.errors.GoogleAdsException as ex:
            print('Request with ID "%s" failed with status "%s" and includes the '
                  'following errors:' % (ex.request_id, ex.error.code().name))
            for error in ex.failure.errors:
                print('\tError with message "%s".' % error.message)
                if error.location:
                    for field_path_element in error.location.field_path_elements:
                        print('\t\tOn field: %s' % field_path_element.field_name)
            sys.exit(1)

        print('Created ad group ad %s.'
              % ad_group_ad_response.results[0].resource_name)

        return ad_group_ad_response


Could you please give a sample of adding new AppAdInfo in python?

Thanks!

Google Ads API Forum Advisor Prod

unread,
Dec 27, 2019, 10:00:31 AM12/27/19
to csx...@gmail.com, adwor...@googlegroups.com
Hi,

Since this is language specific, I'd recommend asking the client library owners for the syntax to creating this.

Regards,
Anthony
Google Ads API Team

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