Ads API to get headline+description of different ad types

1,028 views
Skip to first unread message

EladB

unread,
Aug 31, 2021, 7:33:42 PM8/31/21
to AdWords API and Google Ads API Forum
Hi esteemed,

I want to audit the mandatory fields of a few ads from different types (text ads, extended-text ads, responsive text ads).

How would you do this (python 3.8 compatible)?

I see my select clause should fetch a few fields. How would you switch case the ad type while making sure my code resilient for cases when the `yaml` file doesn't contain `Proto-plus = True` (for enum names: [one], [two])


Thanks!

My code:

    query = f"""
        SELECT
          customer.id,
          campaign.id,
          ad_group_ad.ad.type,
          ad_group_ad.ad.text_ad.headline,
          ad_group_ad.ad.text_ad.description1,
          ad_group_ad.ad.text_ad.description2,
 
          ad_group_ad.ad.expanded_text_ad.headline_part1,
          ad_group_ad.ad.expanded_text_ad.headline_part2,
          ad_group_ad.ad.expanded_text_ad.headline_part3,
 
          ad_group_ad.ad.responsive_search_ad.headlines,
          ad_group_ad.ad.responsive_search_ad.descriptions,
          ad_group_ad.ad.responsive_search_ad.path1,
          ad_group_ad.ad.responsive_search_ad.path2,
 
          ad_group_ad.ad.id,
          ad_group_ad.ad.type,
          ad_group_ad.ad_group,
          ad_group_ad.policy_summary.approval_status,
          ad_group_ad.policy_summary.policy_topic_entries
        FROM ad_group_ad
        WHERE
            ad_group_ad.policy_summary.approval_status = DISAPPROVED"""
 
    customer_id = account["id"]
    rows = serviceWrapper.get_rows(customer_id, query)
    for row in rows:
        ad_group_ad = row.ad_group_ad
        ad = ad_group_ad.ad
        if ad.type_.name.upper() == "TEXT_AD":
                print(
                    f'\tad.text_ad.headline: "{ad.text_ad.headline}", desc1: "{ad.text_ad.description1}", '
                    f'desc2: "{ad.text_ad.description2}"')
            elif ad.type_.name.upper() == "EXPANDED_TEXT_AD":
                print(
                    f'\tad.expanded_text_ad.headline_part1: "{ad.expanded_text_ad.headline_part1}", ad_group_ad.ad.expanded_text_ad.headline_part1: "{ad_group_ad.ad.expanded_text_ad.headline_part1}", '
                    f'ad_group_ad.ad.expanded_text_ad.headline_part2: "{ad_group_ad.ad.expanded_text_ad.headline_part2}"')
            elif ad.type_.name.upper() == "RESPONSIVE_SEARCH_AD":
                print(
                    f'\tad_group_ad.ad.responsive_search_ad.headlines: "{ad_group_ad.ad.responsive_search_ad.headlines}", ad_group_ad.ad.responsive_search_ad.descriptions: "{ad_group_ad.ad.responsive_search_ad.descriptions}", '
                    f'ad_group_ad.ad.responsive_search_ad.path1: "{ad_group_ad.ad.responsive_search_ad.path1}", ad_group_ad.ad.responsive_search_ad.path2: "{ad_group_ad.ad.responsive_search_ad.path2}"')

Elad Ben-David

unread,
Aug 31, 2021, 7:36:09 PM8/31/21
to AdWords API and Google Ads API Forum
Hello,

--

Screen Shot 2015-10-06 at 2.15.09 PM.png

•  Elad Ben-David (He / Him)

 Customer Solutions Engineer

•  el...@google.com

•  Google EEM

Available: Sun - Thur



Mhmoudahmdmohmmd homydt

unread,
Aug 31, 2021, 7:55:41 PM8/31/21
to el...@google.com, AdWords API and Google Ads API Forum


653

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api...@googlegroups.com
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 "AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/4508bfa9-01b1-4674-a700-f97786f86964n%40googlegroups.com.

Mhmoudahmdmohmmd homydt

unread,
Aug 31, 2021, 7:55:49 PM8/31/21
to el...@google.com, AdWords API and Google Ads API Forum


653

Google Ads API Forum Advisor

unread,
Sep 1, 2021, 2:53:20 AM9/1/21
to adwor...@googlegroups.com
Hi Elad,

Thank you for reaching out to our API support team.

You are correct that you should use the ad_group_ad report in fetching specific ad details. However, as it seems that you wish to clarify a code or client library level solution, I would recommend that you reach out to the client library owners instead, via this link, for further guidance.

Best regards,

Google Logo
Peter Laurence Napa Oliquino
Google Ads API Team
 


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