Getting stats from Keyword planner API for specific date range

1,020 views
Skip to first unread message

vib...@nvidia.com

unread,
May 1, 2017, 9:58:34 PM5/1/17
to AdWords API Forum
Hello I'm using the targeting keyword Idea api to extract the search volume of past searches of a speciifc word monthly. In the UI I can set the date range and extract the month by month stats for the specific country for past three years. In API I can get the annual stats. However when I want to get the stats for three years month by month I'm nt able to correctly use the date range feature in the python API of the Google ADWORDS. I get the below error 
TypeNotFound: Type not found: 'DateRange':


This is my script. Please help

from googleads import adwords


PAGE_SIZE = 100

start_date = '20140101'
end_date = '20140101'
def main(client):
  # Initialize appropriate service.
  targeting_idea_service = client.GetService(
      'TargetingIdeaService', version='v201702')

  # Construct selector object and retrieve related keywords.
  offset = 0
  selector = {
      'searchParameters': [
          {
              'xsi_type': 'RelatedToQuerySearchParameter',
              'queries': ['TRUMP DUMP']
          },
          {
              # Language setting (optional).
              # The ID can be found in the documentation:
              #  https://developers.google.com/adwords/api/docs/appendix/languagecodes
              'xsi_type': 'LanguageSearchParameter',
              'languages': [{'id': '1000'}]
          },
          {
              # Network search parameter (optional)
              'xsi_type': 'NetworkSearchParameter',
              'networkSetting': {
                  'targetGoogleSearch': True,
                  'targetSearchNetwork': False,
                  'targetContentNetwork': False,
                  'targetPartnerSearchNetwork': False
              }
          }
      ],
      'ideaType': 'KEYWORD',
      'requestType': 'STATS',
      'requestedAttributeTypes': ['KEYWORD_TEXT', 'SEARCH_VOLUME',
                                  'TARGETED_MONTHLY_SEARCHES'],
      'paging': {
          'startIndex': str(offset),
          'numberResults': str(PAGE_SIZE)
      },
    
        'DateRange':{
            'min': '20140101',
             'max': '20170101'
        }
    
      
    
        
  }

  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']:
          attributes[attribute['key']] = getattr(attribute['value'], 'value',
                                                 '0')
        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['TARGETED_MONTHLY_SEARCHES']))
      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)

vib...@nvidia.com

unread,
May 2, 2017, 1:13:58 AM5/2/17
to AdWords API Forum

Peter Oliquino

unread,
May 2, 2017, 1:41:21 AM5/2/17
to AdWords API Forum
Hi Vibhor,

In the TargetingIdeaService of the AdWords API, only the TARGETED_MONTHLY_SEARCHES attribute type is supported for the Date Range, which ranges to only 12 months as mentioned in this section of the Targeting Ideas guide. However, to further investigate your concern, could you provide the complete screenshot (all filters included) of the Keyword Planner in the AdWords UI wherein you were able to specify a date range for the past three years? Please reply using Reply privately to author.

Thanks and regards,
Peter
AdWords API Team

Jigar Navadiya

unread,
Mar 9, 2018, 4:09:57 AM3/9/18
to AdWords API Forum
Hi there,

I also wanted to get a month on month data using API. What's the solution? Please share here.


Based on your experience with Tatvic, how likely are you to recommend us to a friend or a colleague?

Click on the star to rate (1 being least likely and 5 being most likely)

Thank you for reading this far. This email may be *confidential* or *privileged*. If you received this communication by mistake, please don't forward it to anyone else. Please erase all copies and attachments, and let me know that it went to the wrong person.

Peter Oliquino

unread,
Mar 9, 2018, 4:33:05 AM3/9/18
to AdWords API Forum
Hi Jigar,

As discussed in this guide, you can use the TARGETING_MONTHLY_SEARCHES attribute to retrieve monthly volumes for a period of 12 months. Also, seeing that you have responded to quite an old thread to discuss your concern, I would recommend that you create a new one if you have additional questions, for better tracking.

Best regards,
Peter
AdWords API Team
Reply all
Reply to author
Forward
0 new messages