【发布时间】:2019-10-27 22:46:25
【问题描述】:
GOOGLE_APPLICATION_CREDENTIALS=../storage/app/service-account.json
我在 .env 文件中有一个 google api 凭据密钥。但是,在我运行 php artisan config:cache 后,无法加载凭据。在缓存配置之前它工作正常。
我在 vendor 文件夹中的 google api auth 文件中找到了以下函数。谷歌服务似乎默认使用 .env 。所以在 config:cache 之后,fromEnv 函数会中断。 使用另一种身份验证方法 setAuthConfig('/path/to/client_credentials.json') 解决问题。
/**
* Load a JSON key from the path specified in the environment.
*
* Load a JSON key from the path specified in the environment
* variable GOOGLE_APPLICATION_CREDENTIALS. Return null if
* GOOGLE_APPLICATION_CREDENTIALS is not specified.
*
* @return array JSON key | null
*/
public static function fromEnv()
{
$path = getenv(self::ENV_VAR);
if (empty($path)) {
return;
}
if (!file_exists($path)) {
$cause = 'file ' . $path . ' does not exist';
throw new \DomainException(self::unableToReadEnv($cause));
}
$jsonKey = file_get_contents($path);
return json_decode($jsonKey, true);
}
【问题讨论】:
-
你是如何使用 config.php 中的 env 变量的,你能证明一下吗?
-
我不明白。它是一个带有数据库和电子邮件配置的缓存文件,例如 DB_DATABASE 和 MAIL_USERNAME。
-
您是在配置文件中添加了
GOOGLE_APPLICATION_CREDENTIALS变量还是只在.env文件中添加了它?
标签: laravel-5