首页 > 解决方案 > 开发脚本以从 Google Analytics 中提取数据

问题描述

我正在开发一个 Python 脚本来从 Google Analytics 中提取数据。我正在使用他们文档中的代码。

我还尝试了 Postman 和 Core Reporting API,它们正在工作

我收到此错误:

JSONDecodeError                           Traceback (most recent call last)
cell_name in async-def-wrapper()

cell_name in main()

<ipython-input-17-81b765f9722c> in get_service(api_name, api_version, scopes, key_file_location)
     13 
     14     credentials = ServiceAccountCredentials.from_json_keyfile_name(
---> 15             key_file_location, scopes=scopes)
     16 
     17     # Build the service object.

~/anaconda3/lib/python3.7/site-packages/oauth2client/service_account.py in from_json_keyfile_name(cls, filename, scopes, token_uri, revoke_uri)
    218         """
    219         with open(filename, 'r') as file_obj:
--> 220             client_credentials = json.load(file_obj)
    221         return cls._from_parsed_json_keyfile(client_credentials, scopes,
    222                                              token_uri=token_uri,

~/anaconda3/lib/python3.7/json/__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    294         cls=cls, object_hook=object_hook,
    295         parse_float=parse_float, parse_int=parse_int,
--> 296         parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
    297 
    298 

~/anaconda3/lib/python3.7/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    346             parse_int is None and parse_float is None and
    347             parse_constant is None and object_pairs_hook is None and not kw):
--> 348         return _default_decoder.decode(s)
    349     if cls is None:
    350         cls = JSONDecoder

~/anaconda3/lib/python3.7/json/decoder.py in decode(self, s, _w)
    335 
    336         """
--> 337         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338         end = _w(s, end).end()
    339         if end != len(s):

~/anaconda3/lib/python3.7/json/decoder.py in raw_decode(self, s, idx)
    353             obj, end = self.scan_once(s, idx)
    354         except StopIteration as err:
--> 355             raise JSONDecodeError("Expecting value", s, err.value) from None
    356         return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

标签: google-analyticsjupyter-notebookgoogle-api-python-client

解决方案


尝试使用谷歌查询资源管理器进行 curl 调用https://ga-dev-tools.appspot.com/query-explorer/


推荐阅读