Hi,
I'm trying to use the Google Ads Beta API Interactive Search Query Builder
<https://developers.google.com/google-ads/api/docs/query/interactive-gaql-builder>
with the google-ads-python <https://github.com/googleads/google-ads-python>
Github
repo to gather information for a dashboard. I'm successfully able to
retrieve about half of the information I'm looking for, but some of the
queries created by the Builder either return no data or indicate an error
with the query that I do not understand.
Code I'm using to run the queries:
from __future__ import absolute_import
import argparse
import six
import sys
import google.ads.google_ads.client
_DEFAULT_PAGE_SIZE = 1000
def main(client, customer_id, page_size):
ga_service = client.get_service('GoogleAdsService', version='v2')
# ********************NOTES*********************
# query1 successfully returns data for: campaign.id, campaign.name,
segments.ad_network_type,
segments.device, campaign.shopping_setting.campaign_priority
# query1 returns no data for bidding_strategy.type, language_code,
custom_parameters
query1 = ( 'SELECT campaign.id, campaign.name, '
'segments.ad_network_type, segments.device, '
'bidding_strategy.type, campaign.dynamic_search_ads_setting.language_code,
'
'campaign.shopping_setting.campaign_priority, '
'campaign_budget.type, campaign.url_custom_parameters '
'FROM campaign '
'LIMIT 20')
# query2 returns no data for bidding_strategy.type or name
query2 = ( 'SELECT bidding_strategy.type, bidding_strategy.name, '
'FROM bidding_strategy '
'LIMIT 20')
results = ga_service.search(customer_id, query=query#NUMBER#, page_size
=page_size)
print str(results)
try:
for row in results:
print '******** ROW DATA'
print str(row)
print('Campaign with ID %d and name/Priority "%s" was found.'
% (row.campaign.id.value, row.campaign.shopping_setting.campaign_priority))
# % (row.campaign.id.value, row.campaign.name.value))
except google.ads.google_ads.errors.GoogleAdsException as ex:
print 'Why are you so wrong?'
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)
if __name__ == '__main__':
# GoogleAdsClient will read the google-ads.yaml configuration file in the
# home directory if none is specified.
google_ads_client = (google.ads.google_ads.client.GoogleAdsClient
.load_from_storage())
parser = argparse.ArgumentParser(
description='Lists all campaigns for specified customer.')
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The Google Ads customer ID.')
args = parser.parse_args()
main(google_ads_client, args.customer_id, _DEFAULT_PAGE_SIZE)
Here's a summary of the values I'm searching for, the query language I
provided, and the responses I received.
*Fields that don't work in my queries:*
*- Desired Field : '*query formatting provided by Query Builder'
- *Bid Strategy Type .. this is query2 in the code above*:
'bidding_strategy.type
FROM bidding_strategy'
----> returns no data, when requesting 'FROM campaign' response object
comes back with other requested data but nothing for Bid Strategy Type
----> returns Invalid Argument Error when requesting 'FROM
bidding_strategy' look at 'query2' in code below ..
Terminal Logs for my query2
Dylan-McBurnetts-MacBook-Pro:basic_operations dylanmcburnett$
./get_dylan_data.py -c 2036267401
<google.api_core.page_iterator.GRPCIterator object at 0x10e526310> hello No
handlers could be found for logger "google.ads.google_ads.client" Why are
you so wrong? Request with ID "7CjQwf-ivGcDF1ApnrDmTQ" failed with status
"INVALID_ARGUMENT" and includes the following errors: Error with message
"Error in SELECT clause: invalid field name 'FROM'.".
- *Language Code* : 'campaign.dynamic_search_ads_setting.language_code FROM
campaign'
-----> No data returned
- *Location*: 'location_view.resource_name FROM location_view'
-----> No data returned
- *Active Bid Adjustment*: 'campaign_criterion.bid_modifier FROM
campaign_criterion'
- *Custom Parameters: *'campaign.url_custom_parameters FROM campaign'
*Negative Keywords*: returns an empty object fro the query below
queryNegKey = ( 'SELECT '
'keyword_plan_negative_keyword.id, '
'keyword_plan_negative_keyword.keyword_plan_campaign, '
'keyword_plan_negative_keyword.match_type,
keyword_plan_negative_keyword.resource_name '
'FROM keyword_plan_negative_keyword '
'LIMIT 50' )
-
*Fields that do work: *queries for the values below all work indicating
that my access and permissions are correct as far as I can tell
- Campaign ID: 'campaign.id'
- Campaign Name: 'campaign.name'
- Network : ' segments.ad_network_type'
- Delivery: 'campaign_budget.delivery_method'
- Device: 'segments.device'
- Campaign Priority: 'campaign.shopping_setting.campaign_priority'
- Attribution: 'conversion_action
conversion_action.attribution_model_settings.attribution_model'
How can I properly retrieve my missing values listed above?
Please let me know if there's any additional information I can provide.
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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
"AdWords API and Google Ads 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/0079ec30-2201-443d-9dc9-3bc04a898a22%40googlegroups.com.