TargetingIdeaService - INVALID SEARCH PARAMETERS - Python

53 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
Running python code example but running into an error that doesn't make sense:

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



I'm using the code exactly as written off the github repository. No problems with oauth or anything else - already have developer code, etc. 
Code:


from googleads import adwords



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)




Teja Makani

unread,
Sep 21, 2018, 3:44:49 PM9/21/18
to AdWords API and Google Ads API Forum
Hello Scott,

I see that you have opened one more thread for this concern. To avoid duplication lets continue our discussion on this thread only. Please find my response below:

The TargetingIdeaError.INVALID_SEARCH_PARAMETERS error occurs when a SearchParameter does not match the IdeaType specified in the TargetingIdeaSelector or is otherwise invalid. Looks like you are trying to run get_keyword_ideas.py. I ran the same example commenting out the optional lines and able to fetch the results for keyword ideas. Even I ran your code and it works fine. If the problem persists could you please share the SOAP logs(request and response) without redacting any information. Please follow the instruction shown in this README.md file to enable logging. 

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