python - 如何在 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。
想得到帮助!谢谢。
解决方案
推荐阅读
- android - 改造不会序列化我的响应类中的第二个对象
- python - Sklearn 目标数据 - 只有整数标量可以转换为标量索引
- django - 如何将 slug 传递给 Django 中的 URL?
- javascript - Discord 在消息字符串中添加逗号
- json - 在将 XML 转换为 JSON 时如何使用 XSLT 忽略 XML 中的“”?
- vue.js - 如何在 Nuxt Axios API 调用中创建自动相对基本 URL(用于未知部署域)
- javascript - 将值从 JSON 对象推送到数组并使用外部函数
- arrays - 数组中的 Golang 指针
- git - 找不到命令“git.clone”
- algorithm - 随机数生成器,为每个种子产生相同的顺序,最大值不高于循环长度,索引或值没有紧密形式