通过dashbord脚本js调用python方法

时间:2017-03-01 11:10:08

标签: javascript php python google-analytics

我有python脚本通过服务帐户获取google-api-for-python的访问令牌已知我的项目是php web app 我遵循本教程[Embed-Api] https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/

我已经使用json-key将脚本放在我的项目中,并进行了所有必需的更改,这是我的python脚本。

# service-account.py
from oauth2client.service_account import ServiceAccountCredentials

# 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 = 'home/mousa/json-key.json'

# Defines a method to get an access token from the ServiceAccount object.
def get_access_token():
  print ServiceAccountCredentials.json-key.json(KEY_FILEPATH, SCOPE).get_access_token().access_token

现在这里是 js ,我想调用get_access_token()方法:

gapi.analytics.auth.authorize({
  'serverAuth': {
    'access_token': '{{"invoke get_access_token()!!?"}'
  }
});

我如何调用方法并确保输出将是访问令牌?

0 个答案:

没有答案