首页 > 解决方案 > 如何在 Heroku 上创建 Flow 对象-凭据

问题描述

所以我尝试了这个链接中提到的一些建议 - https://stackoverflow.com/questions/47446480/how-to-use-google-api-credentials-json-on-heroku。首先,我在 Heroku(GOOGLE_APPLICATION_CREDENTIALS,GOOGLE_CREDENTIALS) 上设置了一个配置变量,它确实加载了凭据。但我在创建 Flow 对象时仍然出错,我尝试了@Chrisjan 在链接中建议的内容并将这一行添加到 .procfile -

echo ${GOOGLE_CREDENTIALS} > /app/credentials.json

但我在创建流对象时仍然遇到错误。

我的代码:

json_str = os.environ.get('GOOGLE_CREDENTIALS')
client_secrets_dict = json.loads(json_str)

def create_flow():
flow = Flow.from_client_secrets_file(
    client_secrets_file=client_secrets_filename,
    scopes=['openid', 'https://www.googleapis.com/auth/userinfo.profile',
            'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/gmail.readonly'],
    redirect_uri=client_secrets_dict['web']['redirect_uris'][1]
)
return flow

问题出在 create_flow 函数中,在 client_secrets_file=client_secrets_filename 行中。

client_secrets_filename 等于:尝试-1。“credentials.json” 2. “/app/credentials.json”

我也尝试使用 buildpack,但它对我不起作用。我的第一个目的是在这些行中使用 credentials.json,而无需将文件上传到 GitHub。

想得到帮助!谢谢。

标签: pythonherokugoogle-apicredentialsflow

解决方案


推荐阅读