Parsing Response from TargetingIdeaService with Python client library

253 views
Skip to first unread message

Owen Ball

unread,
Dec 1, 2014, 4:17:05 AM12/1/14
to adwor...@googlegroups.com
Hi,

I've been using looking at the sample code to generate keyword idea provided here:


Everything works fine except the parsing of the response data which doesn't look correct to me. Can someone clarify if this is expected behaviour?

This is the code provided to parse and print out the results:

if 'entries' in page:
for result in page['entries']:
attributes = {}
for attribute in result['data']:
attributes[attribute['key']] = attribute['value']
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']))

From this, I would expect to get something along the lines of following:

Keyword with [my keyword] text and average monthly search volume [X] was found with Products and Services categories: [A, B, C].

What I'm actually seeing is more like this with the full attribute information:

Keyword with '(StringAttribute){
   Attribute.Type = "StringAttribute"
   value = "banff"
 }' text and average monthly search volume '(LongAttribute){
   Attribute.Type = "LongAttribute"
   value = 135000
 }
...

I'm certain I'm missing something obvious here so any pointers in the right direction would be most appreciated.



Ogilvy & Mather Group (Holdings) Ltd i
s a company registered in England and Wales with registration number 45810.
Registered office: 10 Cabot Square, Canary Wharf, London E14 4QB. VAT number: GB 189 8416 47

Josh Radcliff (AdWords API Team)

unread,
Dec 1, 2014, 10:14:24 AM12/1/14
to adwor...@googlegroups.com
Hi,

It's not you - it's the example. :)

The printing section isn't navigating deeply enough through the object hierarchy. If you change lines 78 and 79 from:

for attribute in result['data']:
          attributes[attribute['key']] = attribute['value']
to:

         for attribute in result['data']:
          attribute_value = attribute['value']
          if 'value' in attribute_value:
            attributes[attribute['key']] = attribute_value['value']
          else:
            attributes[attribute['key']] = []

then the example should print values as expected. I'll work on getting the example fixed in an upcoming release. Thanks for pointing this out!

Cheers,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages