TargetingIdeaService Request - Python - INVALID SEARCH PARAMETERS

340 views
Skip to first unread message

Sken...@franklinsports.com

unread,
Sep 21, 2018, 5:34:17 AM9/21/18
to AdWords API and Google Ads API Forum
I'm attempting to pull keyword planner data from the API using the python lib examples.

I continue to get the following error: 

suds.WebFault: Server raised fault: '[TargetingIdeaError.INVALID_SEARCH_PARAMETERS @ selector.searchParameters.searchParameters[0]; trigger:'RelatedToQuerySearchParameter']'




I'm very confused on this error as I'm following the documentation exactly. Please help!


AD_GROUP_ID = None
PAGE_SIZE = 100

def main(client, ad_group_id=None):
  # Initialize appropriate service.
  targeting_idea_service = client.GetService(
      'TargetingIdeaService', version='v201802')

  # Construct selector object and retrieve related keywords.
  selector = {
      'ideaType': 'KEYWORD',
      'requestType': 'IDEAS'
  }

  selector['requestedAttributeTypes'] = [
      'KEYWORD_TEXT', 'SEARCH_VOLUME', 'CATEGORY_PRODUCTS_AND_SERVICES']

  offset = 0
  selector['paging'] = {
      'startIndex': str(offset),
      'numberResults': str(PAGE_SIZE)
  }

  selector['searchParameters'] = [{
      'xsi_type': 'RelatedToQuerySearchParameter',
      'queries': ['baseball']
  }]

  # # Language setting (optional).
  # selector['searchParameters'].append({
  #     # The ID can be found in the documentation:
  #     'xsi_type': 'LanguageSearchParameter',
  #     'languages': [{'id': '1000'}]
  # })

  # # Network search parameter (optional)
  # selector['searchParameters'].append({
  #     'xsi_type': 'NetworkSearchParameter',
  #     'networkSetting': {
  #         'targetGoogleSearch': True,
  #         'targetSearchNetwork': False,
  #         'targetContentNetwork': False,
  #         'targetPartnerSearchNetwork': False
  #     }
  # })

  # # Use an existing ad group to generate ideas (optional)
  # if ad_group_id is not None:
  #   selector['searchParameters'].append({
  #       'xsi_type': 'SeedAdGroupIdSearchParameter',
  #       'adGroupId': ad_group_id
  #   })

  more_pages = True
  while more_pages:
    page = targeting_idea_service.get(selector)

    # Display results.
    if 'entries' in page:
      for result in page['entries']:
        attributes = {}
        for attribute in result['data']:
          attribute_value = attribute['value']
          if 'value' in attribute_value:
            attributes[attribute['key']] = attribute_value['value']
          else:
            attributes[attribute['key']] = []
        print ('Keyword with "%s" text and average monthly search volume '
               '"%s" was found with Products and Services categories: %s.'
               % (attributes['KEYWORD_TEXT'],
                  attributes['SEARCH_VOLUME'],
                  attributes['CATEGORY_PRODUCTS_AND_SERVICES']))
      print
    else:
      print 'No related keywords were found.'
    offset += PAGE_SIZE
    selector['paging']['startIndex'] = str(offset)
    more_pages = offset < int(page['totalNumEntries'])


if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()

  main(adwords_client)


AD_GROUP_ID
= None
PAGE_SIZE = 100

def main(client, ad_group_id=None):
 # Initialize appropriate service.
 targeting_idea_service = client.GetService(
     'TargetingIdeaService', version='v201802')

  # Construct selector object and retrieve related keywords.
 selector = {
     'ideaType': 'KEYWORD',
     'requestType': 'IDEAS'
 }

  selector['requestedAttributeTypes'] = [
     'KEYWORD_TEXT', 'SEARCH_VOLUME', 'CATEGORY_PRODUCTS_AND_SERVICES']

  offset = 0
 selector['paging'] = {
     'startIndex': str(offset),
     'numberResults': str(PAGE_SIZE)
 }

  selector['searchParameters'] = [{
     'xsi_type': 'RelatedToQuerySearchParameter',
     'queries': ['baseball']
 }]

  # # Language setting (optional).
 # selector['searchParameters'].append({
 #     # The ID can be found in the documentation:
 #     'xsi_type': 'LanguageSearchParameter',
 #     'languages': [{'id': '1000'}]
 # })

  # # Network search parameter (optional)
 # selector['searchParameters'].append({
 #     'xsi_type': 'NetworkSearchParameter',
 #     'networkSetting': {
 #         'targetGoogleSearch': True,
 #         'targetSearchNetwork': False,
 #         'targetContentNetwork': False,
 #         'targetPartnerSearchNetwork': False
 #     }
 # })

  # # Use an existing ad group to generate ideas (optional)
 # if ad_group_id is not None:
 #   selector['searchParameters'].append({
 #       'xsi_type': 'SeedAdGroupIdSearchParameter',
 #       'adGroupId': ad_group_id
 #   })

  more_pages = True
 while more_pages:
   page = targeting_idea_service.get(selector)

    # Display results.
   if 'entries' in page:
     for result in page['entries']:
       attributes = {}
       for attribute in result['data']:
         attribute_value = attribute['value']
         if 'value' in attribute_value:
           attributes[attribute['key']] = attribute_value['value']
         else:
           attributes[attribute['key']] = []
       print ('Keyword with "%s" text and average monthly search volume '
              '"%s" was found with Products and Services categories: %s.'
              % (attributes['KEYWORD_TEXT'],
                 attributes['SEARCH_VOLUME'],
                 attributes['CATEGORY_PRODUCTS_AND_SERVICES']))
     print
   else:
     print 'No related keywords were found.'
   offset += PAGE_SIZE
   selector['paging']['startIndex'] = str(offset)
   more_pages = offset < int(page['totalNumEntries'])


if __name__ == '__main__':
 # Initialize client object.
 adwords_client = adwords.AdWordsClient.LoadFromStorage()

  main(adwords_client)











gw0...@rmn.com

unread,
Oct 5, 2018, 7:15:07 PM10/5/18
to AdWords API and Google Ads API Forum
One thing you can try is to provide client_customer_id. Although it is listed as optional in googleads.yaml, I found out when using targeting_idea_service that field is actually required.


This e-mail, including attachments, contains confidential and/or proprietary information, and may be used only by the person or entity to which it is addressed. The reader is hereby notified that any dissemination, distribution or copying of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and delete this e-mail immediately.

tom.wa...@raisingit.com

unread,
Oct 12, 2018, 5:58:37 AM10/12/18
to AdWords API and Google Ads API Forum
But it looks like you've forgotten to pass googleads.yaml to the script at all.

The penultimate line should be 

adwords_client = adwords.AdWordsClient.LoadFromStorage("googleads.yaml") # or whatever the right path is

Let me know if you have any luck with this. I can interface with the TargetingIdeaService without any permissions issues or errors, but it often returns an empty result set. The API team has recognised that there is a problem with the Python library and I'm waiting to find out when they'll fix it.

Cheers,
Tom

Teja Makani

unread,
Oct 12, 2018, 11:57:24 AM10/12/18
to AdWords API and Google Ads API Forum
Hello Scott,

Were you able to resolve the issue? Please let me know if you are still facing the issue.

Regards,
Sai Teja, AdWords API Team.
Reply all
Reply to author
Forward
0 new messages