Can Google Analytics API be accessed with service account?

3 views
Skip to first unread message

LA_ via StackOverflow

unread,
Apr 8, 2014, 7:51:12 AM4/8/14
to google-appengin...@googlegroups.com

I would like to show Google Analytics data (for android app) on my GAE web page. I've done the following:

  1. enabled Google Analytics API for my app in Developer's console;
  2. gave access to mya...@appspot.gserviceaccount.com to my Google Analytics.

The following code:

credentials = AppAssertionCredentials(scope='https://www.googleapis.com/auth/analytics.readonly')
http = credentials.authorize(httplib2.Http(memcache))
service = build('analytics', 'v3', http=http)
response1 = service.management().accounts().list().execute()
response2 = service.data().ga().get(
  ids='ga:45112345', # my profile id
  start_date='2014-04-07',
  end_date='2014-04-07',
  metrics='ga:visits').execute()

returns the following responses:

{
   u'username':u'mya...@appspot.gserviceaccount.com',
   u'kind':u'analytics#accounts',
   u'items':[
      {
         u'kind':u'analytics#account',
         u'name':u'myapp - android',
         u'created':         u'2013-10-25T18:31:11.271         Z',
         u'updated':         u'2013-10-25T18:31:11.271         Z',
         u'childLink':{
            u'href':            u'https://www.googleapis.com/analytics/v3/management/accounts/45112345/webproperties',
            u'type':u'analytics#webproperties'
         },
         u'id':u'45112345',
         u'selfLink':         u'https://www.googleapis.com/analytics/v3/management/accounts/45112345',
         u'permissions':{
            u'effective':[
               u'COLLABORATE',
               u'EDIT',
               u'MANAGE_USERS',
               u'READ_AND_ANALYZE'
            ]
         }
      }
   ],
   u'itemsPerPage':1000,
   u'startIndex':1,
   u'totalResults':1
}

<HttpError 403 when requesting https://www.googleapis.com/analytics/v3/data/ga?metrics=ga%3Avisits&alt=json&end-date=2014-04-07&ids=ga%3A45112345&start-date=2014-04-07 returned "User does not have sufficient permissions for this profile.">

Why do I get this User does not have sufficient permissions for this profile error? User has the full access to Google Analytics.

Actually I am just testing how it works. In result I would like to access the following data from Google Analytics:

  1. number of active users in previous week;
  2. screen views
  3. events statistics


Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/22936037/can-google-analytics-api-be-accessed-with-service-account
Reply all
Reply to author
Forward
0 new messages