Search code examples
pandasgoogle-apigoogle-analytics-api

invalid value error in get_report function


def get_report(analytics):
  return analytics.reports().batchGet(
      body={
              'reportRequests': 
              [
                  {
                    'viewId': VIEW_ID,
                    'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],
                    'metrics': [{'expression':i} for i in METRICS],
                    'dimensions': [{'name':j} for j in DIMENSIONS]
                  }
              ]
           }
  ).execute()

File "/home/mail_name/gaToPandas/lib/python3.5/site-packages/googleapiclient/http.py", line 851, in execute raise HttpError(resp, content, uri=self.uri) googleapiclient.errors.HttpError: https://analyticsreporting.googleapis.com/v4/reports:batchGet?alt=json returned "Invalid value '[email protected]' for viewId parameter.">

How can I resolve this issue? There is an error in step 3 of this site https://www.digishuffle.com/blogs/google-analytics-reporting-python/


Solution

  • "Invalid value '[email protected]' for viewId parameter."

    enter image description here

    The view Id should be the view id from Google Analytics which you wish to request data for not the service account name.

    enter image description here