Google Analytics and Python

analytics, google-analytics, google-analytics-api, python

Solution

Maybe this post can help out. Seems like there are not Analytics specific bindings yet, so you are working with the generic gdata.

Problem

I'm brand new at Python and I'm trying to write an extension to an app that imports GA information and parses it into MySQL. There is a shamfully sparse amount of infomation on the topic. The Google Docs only seem to have examples in JS and Java... ...I have gotten to the point where my user can authenticate into GA using SubAuth. That code is here: ``` import gdata.service import gdata.analytics from django import http from django import shortcuts from django.shortcuts import render_to_response def authorize(request): next = 'http://localhost:8000/authconfirm' scope = 'https://www.google.com/analytics/feeds' secure = False # set secure=True to request secure AuthSub tokens session = False auth_sub_url = gdata.service.GenerateAuthSubRequestUrl(next, scope, secure=secure, session=session) return http.HttpResponseRedirect(auth_sub_url) ``` So, step next is getting at the data. I have found this library: (beware, UI is offensive) http://gdata-python-client.googlecode.com/svn/trunk/pydocs/gdata.analytics.html However, I have found it difficult to navigate. It seems like I should be gdata.analytics.AnalyticsDataEntry.getDataEntry(), but I'm not sure what it is asking me to pass it. I would love a push in the right direction. I feel I've exhausted google looking for a working example. Thank you!! EDIT: I have gotten farther, but my problem still isn't solved. The below method returns data (I believe).... the error I get is: "'str' object has no attribute '_BecomeChildElement'" I believe I am returning a feed? However, I don't know how to drill into it. Is there a way for me to inspect this object? ``` def auth_confirm(request): gdata_service = gdata.service.GDataService('iSample_acctSample_v1.0') feedUri='https://www.google.com/analytics/feeds/accounts/default?max-results=50' # request feed feed = gdata.analytics.AnalyticsDataFeed(feedUri) print str(feed) ```

Original source