如何使用密钥文件(PHP / Laravel)对SpeechClient V1进行身份验证

时间:2019-04-05 12:01:21

标签: php laravel google-cloud-platform speech-to-text google-speech-api

我正在尝试使用'keyFilePath'和'projectId'参数来对SpeechClient进行身份验证,如下所示:

$speech = new SpeechClient([
            'projectId' => 'actualProjectId,
            'keyFilePath' => $key_path,
        ]);

如果我使用Google\Cloud\Speech\SpeechClient-一切正常,但是如果我使用Google\Cloud\Speech\V1\SpeechClient,我将得到一个错误:Could not construct ApplicationDefaultCredentials

我已经读过Google docs for Setting Up Authentication,但仍然不明白我在做什么错。

我需要V1(实际上是V1p1beta1)才能使用旧的SpeechClient无法获得的其他功能。

有什么想法吗?

P.S。使用Laravel作为后端。

1 个答案:

答案 0 :(得分:1)

对于V1等命名空间中的客户端,将keyFilePath作为credentials传递。

new SpeechClient([
    'credentials' => $key_path
]);
相关问题