Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Google Analytics服务器端授权到期_Python_Google Analytics_Google Api_Google Oauth - Fatal编程技术网

Python Google Analytics服务器端授权到期

Python Google Analytics服务器端授权到期,python,google-analytics,google-api,google-oauth,Python,Google Analytics,Google Api,Google Oauth,我正在创建一个管理仪表板,并希望显示来自谷歌分析的图表。为此,我按照找到的服务器端授权的步骤进行了操作。在本例结束之前,一切都很好。问题是访问令牌在一小时后过期,需要重新生成 我找不到有关如何刷新此令牌的详细信息。有没有办法自动刷新此令牌 import json from oauth2client.client import SignedJwtAssertionCredentials # The scope for the OAuth2 request. SCOPE = 'https://ww

我正在创建一个管理仪表板,并希望显示来自谷歌分析的图表。为此,我按照找到的服务器端授权的步骤进行了操作。在本例结束之前,一切都很好。问题是访问令牌在一小时后过期,需要重新生成

我找不到有关如何刷新此令牌的详细信息。有没有办法自动刷新此令牌

import json
from oauth2client.client import SignedJwtAssertionCredentials

# The scope for the OAuth2 request.
SCOPE = 'https://www.googleapis.com/auth/analytics.readonly'

# The location of the key file with the key data.
KEY_FILEPATH = 'path/to/json-key.json'

# Load the key file's private data.
with open(KEY_FILEPATH) as key_file:
  _key_data = json.load(key_file)

# Construct a credentials objects from the key data and OAuth2 scope.
_credentials = SignedJwtAssertionCredentials(
    _key_data['client_email'], _key_data['private_key'], SCOPE)

# Defines a method to get an access token from the credentials object.
# The access token is automatically refreshed if it has expired.
def get_access_token():
  return _credentials.get_access_token().access_token

print get_access_token()