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()