How to get more than 700 results from TargetingIdeas Service on python

131 views
Skip to first unread message

Santiago O

unread,
Mar 22, 2021, 8:32:06 AM3/22/21
to AdWords API and Google Ads API Forum

Good morning,

I'm trying to get more than 700 (the upper limit) keywords from the TargetingIdeas Service. According to the available documentation, I should be able to do so by increasing the "startIndex" parameter at each request, but I can't get the code to work.

I'm doing the following: I'm targeting a specific CategoryId, requesting 500 at a time on the "numberResults" parameter, and then increse the "startIndex" parameter by 500 each time.

This is not working, so I have just tried to set to 500 both parameters, which should give me elements from 500 to 1000. But this is not the case, as I only manage to get elements from 500 to 700, thus being unable to overcome that limit...

The startIndex has clearly been modified, as I'm getting elements starting from the 500, but for some reason the 700 limit is still there, as if this 700 limit wasn't a request limit, but a global limit.

Could you please help me? Here it is the code I have been using for this last test:


PAGE_SIZE = 500

def main(client):
 
  Categories = [10004]
 
  for elem in Categories:  
 
    targeting_idea_service = adwords_client.GetService('TargetingIdeaService', version='v201809')

    # Construct selector
    selector = {
        'ideaType': 'KEYWORD',
        'requestType': 'IDEAS'
    }
 
    selector['requestedAttributeTypes'] = [
        'KEYWORD_TEXT', 'SEARCH_VOLUME', 'CATEGORY_PRODUCTS_AND_SERVICES', 'COMPETITION','AVERAGE_CPC']
 
    offset = 500
    selector['paging'] = {
        'startIndex': str(offset),
        'numberResults': str(PAGE_SIZE)
    }
 
    selector['searchParameters'] = [{
        'xsi_type': 'CategoryProductsAndServicesSearchParameter',
        'categoryId': elem
    }]
 
    selector['searchParameters'].append({
      'xsi_type': 'NetworkSearchParameter',
      'networkSetting': {
          'targetGoogleSearch': True,
          'targetSearchNetwork': True,
          'targetContentNetwork': False,
          'targetPartnerSearchNetwork': True
      }
    })

    selector['searchParameters'].append({
        'xsi_type': 'LanguageSearchParameter',
        'languages': [{'id': '1000'}] #English
        
    })
    
    selector['searchParameters'].append({
        'xsi_type': 'LocationSearchParameter',
        'locations': [{'id': '2840'}]  # United States
    })


    for i in range(5):
      try:
        page = targeting_idea_service.get(selector)
        break
        
      except Exception as e:
        print("ERROR: " + str(e))
        time.sleep(30)  
        
    for result in page['entries']:
      attributes = {}
      for attribute in result['data']:
        attributes[attribute['key']] = getattr(attribute['value'], 'value', '0')

Google Ads API Forum Advisor Prod

unread,
Mar 22, 2021, 3:58:16 PM3/22/21
to sant...@pearchdigital.com, adwor...@googlegroups.com

Hi Santiago,

Thank you for reaching out. Please give it a try to use this code example and when you make the second call, set 700 on this line. And for the third call set 1400 to the offset, so on and so forth.

Thanks and regards,
Xiaoming, Google Ads API Team


Google Logo
Xiaoming
Google Ads API Team
 


ref:_00D1U1174p._5004Q2DxgAu:ref

Santiago O

unread,
Mar 23, 2021, 5:48:52 AM3/23/21
to AdWords API and Google Ads API Forum
Good morning,

First of all, thank you very much for the assistance.

I'm sorry but I get the same issue. In fact, the variable page['totalNumEntries'], which should store the total number of results available, is set to 700.

If tried to call the example code you sent me several times, with the offset set to 700 and 1400, but nothing happens then. It's the same issue I get with my original program.

It seems that, no matter how much I try to increase the offset, the total amount of results available is always 700. Therefore, when the offset exceeds 700, I get nothing.

What may be causing this? In theory, I should be able to access much more results, shouldn't I?

Thank you.


Regards

Google Ads API Forum Advisor Prod

unread,
Mar 23, 2021, 4:00:09 PM3/23/21
to sant...@pearchdigital.com, adwor...@googlegroups.com

Hi Santiago,

Thank you for reaching out. It looks like the maximum number of results for TargetingIdeaService.get() is 700 so this is the maximum number of keyword ideas that could be generated using this service. I would encourage you to use the KeywordPlanIdeaService.GenerateKeywordIdeas() via the Google Ads API. By using this service, the maximum number of returned results for each page is 10,000. If the result set is more than 10,000, you could specify the page_token with the next_page_token obtained from the previous response to continue on the previous page. 



Thanks and regards,
Xiaoming, Google Ads API Team
 

Santiago O

unread,
Mar 24, 2021, 1:43:56 PM3/24/21
to AdWords API and Google Ads API Forum
Hi Xiaoming,

Thanks a lot for the help. Nevertheless, here's no way of getting keywords by category with this method, isn't it? I can provide a seed keyword or url, but I can't provide a category ID as possible on the TargetIdeaService.get().

Nevertheless, this might be enough. Could you give me a piece of example code, as you did previously? That will easy my work a lot.


Thank you a lo in advance, and best regards,

Santiago

Google Ads API Forum Advisor Prod

unread,
Mar 25, 2021, 1:53:45 AM3/25/21
to sant...@pearchdigital.com, adwor...@googlegroups.com
Hi Santiago,

I work with Xiaoming and allow me to assist you.

Regarding keywords by category, unfortunately, it would not be possible to get this via the APIs. 

For the sample code on the KeywordPlanIdeaService, you can check out this link. I hope this helps.

Best regards,

Google Logo
Peter Laurence Napa Oliquino
Google Ads API Team
 


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