Assistance with a Python code

151 views
Skip to first unread message

Ujval Gandhi

unread,
Jul 14, 2021, 10:57:21 PM7/14/21
to AdWords API and Google Ads API Forum
Team

I am having some issues trying to get the code to work and download the data in a csv format

customer_service = client.get_service("CustomerService")
resource_name = customer_service.customer_path(customer_id)
customer = customer_service.get_customer(resource_name=resource_name)
ga_service = client.get_service("GoogleAdsService")

query = """
    SELECT
  campaign.status, 
  ad_group.campaign, 
  ad_group.status, 
  ad_group_ad.ad.final_urls,
  metrics.impressions,
  metrics.clicks,
  metrics.cost_micros,
  metrics.engagements, 
  metrics.interactions,  
  segments.date
FROM ad_group_ad
WHERE segments.date BETWEEN '2021-01-01' AND '2021-07-13'
"""

search_request = client.get_type("SearchGoogleAdsRequest")
search_request.customer_id = customer_id
search_request.query = query


results = ga_service.search(request=search_request)

for row in results:
    
    campaign = row.campaign
    ad_group = row.ad_group
    ad_group_ad  = row.ad_group_ad
    metrics = row.metrics
    segments = row.segments

    df = pd.DataFrame({ 
                       'campaignid': [campaign.id], 
                       'campaignname': [campaign.name],
                       'campaignstatus': [campaign.status],
                       'AdGroup': [ad_group.name],
                       'AdGroupStatus': [ad_group.status],
                       'ad_group_ad.adname': [ad_group_ad.ad.name],                                       
                       'ad_group_ad.ad_finalurls': [ad_group_ad.ad.final_urls],
                       'impressions': [metrics.impressions],
                       'clicks': [metrics.clicks] ,
                       'cost': [metrics.cost_micros], 
                       'engagements': [metrics.engagements] ,
                       'interactions': [metrics.interactions],                     
                       'date': [segments.date]                      
                       }) 


I ran the code but it only give me data for 7/13/2021. What am I missing?

Regards

Google Ads API Forum Advisor

unread,
Jul 15, 2021, 4:26:38 PM7/15/21
to ujval....@gmail.com, adwor...@googlegroups.com
Hello,

Thanks for reaching out. Can you please provide us with the complete request and response logs so that we can take a closer look?

Thanks,
Matt
Google Ads API Team

Google Logo
Matt
Google Ads API Team
 


ref:_00D1U1174p._5004Q2KcQGK:ref
Message has been deleted

Google Ads API Forum Advisor

unread,
Jul 16, 2021, 10:38:48 AM7/16/21
to ujval....@gmail.com, adwor...@googlegroups.com
Hello,

Thanks for sending over more information. However for our team to best investigate, can you please provide us with the complete request and response? We do not need the Python code, just the request and response returned. 
Message has been deleted

Google Ads API Forum Advisor

unread,
Jul 20, 2021, 11:17:41 PM7/20/21
to ujval....@gmail.com, adwor...@googlegroups.com
Hi Ujval,

I work with Matt and allow me to assist you as well.

From the attachments you provided, our team is unable to identify whether there is indeed an issue in your request. In the UI's Ads view, it also appears that your ads started to serve only from February, 2021. That said, the segments.date BETWEEN '2021-01-01' AND '2021-07-13' filter, specifically the '2021-01-01' is a bit too far a date range.

You can enable logging by navigating to the Client libraries > Your client library (ex. Java) > Logging documentation, which you can access from this link. Once enabled you may then provide the complete request and response logs (with the request-id).

You can send the requested information via the Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

Best regards,

Google Logo
Peter Laurence Napa Oliquino
Google Ads API Team
 


ref:_00D1U1174p._5004Q2KcQGK:ref

Google Ads API Forum Advisor

unread,
Jul 21, 2021, 1:56:57 AM7/21/21
to ujval....@gmail.com, adwor...@googlegroups.com
Hi Ujval,

I also had to delete your recent responses as those contained details of your logs. For sending logs, you may send those privately instead or directly to our alias.
Reply all
Reply to author
Forward
0 new messages