From 1b89685ec8ea415641198e3013ed3904dc3cdcdb Mon Sep 17 00:00:00 2001 From: dmpe Date: Wed, 12 Dec 2018 23:08:24 +0000 Subject: [PATCH] still the same stuff of loading ga python class #12 --- userMng/third_party_services/google_analytics.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/userMng/third_party_services/google_analytics.py b/userMng/third_party_services/google_analytics.py index 580f38b31..60dde7ea6 100644 --- a/userMng/third_party_services/google_analytics.py +++ b/userMng/third_party_services/google_analytics.py @@ -7,9 +7,7 @@ class Google_Analytics: https://developers.google.com/analytics/devguides/reporting/core/dimsmets https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-py """ - SCOPES = ['https://www.googleapis.com/auth/analytics.readonly'] - KEY_FILE_LOCATION = 'client_secrets.json' - VIEW_ID = '181239651' + def initialize_analyticsreporting(self): """ @@ -18,8 +16,9 @@ def initialize_analyticsreporting(self): Returns: An authorized Analytics Reporting API V4 service object. """ - - credentials = ServiceAccountCredentials.from_json_keyfile_name(KEY_FILE_LOCATION, SCOPES) + SCOPES = ['https://www.googleapis.com/auth/analytics.readonly'] + KEY_FILE_LOCATION = 'client_secrets.json' + credentials = ServiceAccountCredentials.from_json_keyfile_name(self.KEY_FILE_LOCATION, self.SCOPES) # Build the service object. analytics = build('analyticsreporting', 'v4', credentials=credentials) @@ -37,11 +36,12 @@ def get_report(self, analytics): The Analytics Reporting API V4 response. """ + VIEW_ID = '181239651' return analytics.reports().batchGet( body={ 'reportRequests': [ { - 'viewId': VIEW_ID, + 'viewId': self.VIEW_ID, 'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}], 'metrics': [{'expression': 'ga:sessions', "expression":"ga:pageviews"}], 'dimensions': [{'name': 'ga:country', "name":"ga:browser"}]