Python error on generate call

32 views
Skip to first unread message

Samuel Stoddard

unread,
Nov 17, 2011, 4:35:31 PM11/17/11
to adsen...@googlegroups.com
Hi!  I'm trying to use the AdSense Management API with Python 2.6.5 to retrieve earnings data.  I make it past the oauth step fine, and I can get a report consisting of a single column just fine:

result = service.reports().generate(
    startDate = "2011-01-01",
    endDate = "2011-02-01",
    filter = ("AD_CLIENT_ID==%s" % ad_client_id),
    metric = "PAGE_VIEWS",
    dimension = "DATE",
    sort = "+DATE"
).execute()

This returns data that looks correct.  However, if I try to pass in lists for any parameter, I get the Python error "TypeError: expected string or buffer".  For example, this code returns that Python error:

result = service.reports().generate(
    startDate = "2011-01-01",
    endDate = "2011-02-01",
    filter = ("AD_CLIENT_ID==%s" % ad_client_id),
    metric = ["PAGE_VIEWS","EARNINGS"],
    dimension = "DATE",
    sort = "+DATE"
).execute()

Passing in lists is what the bottom of http://code.google.com/apis/adsense/management/v1/complete_guide.html says to do, and it was only by fiddling around and trying things at random that I discovered it worked if you just pass in strings instead of lists.  But I can't get multiple columns this way.  I did try setting metric to "PAGE_VIEWS,EARNINGS" to see if a comma-delimited string would work, but then the response from the call to www.googleapis.com comes back with "Invalid value 'PAGE_VIEWS,EARNINGS'. Values must match the following regular expression: '[a-zA-Z_]+'"

Any ideas?  Thanks.

Silvano Luciani

unread,
Nov 18, 2011, 3:26:21 PM11/18/11
to AdSense API Forum
Hello Samuel,

passing in lists is the correct way of doing it.
The problem was due to a bug that has been fixed in this review of the
Google API Python client:
http://code.google.com/p/google-api-python-client/source/detail?r=8cdc89358232e2ba89d5abf4d225fe58b34587ae

Please get a local copy of the google-api-python-client repository and
use it until a new version of the client will be packaged and
released.
You can find instructions here:
http://code.google.com/p/google-api-python-client/source/checkout

Thanks for your post that helped us to find and fix that bug!

Cheers,
Silvano

--
Silvano Luciani | Developer Programs Engineer

Google UK Limited
Registered Office: Belgrave House, 76 Buckingham Palace Road, London
SW1W 9TQ
Registered in England Number: 3977902
> then the response from the call towww.googleapis.comcomes back with
Reply all
Reply to author
Forward
0 new messages