【发布时间】:2018-12-02 23:09:53
【问题描述】:
我有一个节点应用程序,我正在尝试使用谷歌语言 api。我想将环境变量 GOOGLE_APPLICATION_CREDENTIALS 设置为同一目录中的 json 文件(与 package.json 和 app.js 同级)。
我曾在我的 app.js 文件中尝试过 process.env.GOOGLE_APPLICATION_CREDENTIALS = "./key.json";(使用 express),但它不起作用。我也尝试将"GOOGLE_APPLICATION_CREDENTIALS":"./key.json" 放在我的 package.json 中,但效果不佳。当我在终端 export GOOGLE_APPLICATION_CREDENTIALS="./key" 中运行时,它确实有效。
这是错误信息:
ERROR: Error: Unexpected error while acquiring application default credentials: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information.
感谢任何提示,谢谢!
【问题讨论】:
标签: node.js google-cloud-platform environment-variables