如何在PHP应用程序中验证GoogleCloudSpeech-To-Text客户端?
对于 PHP 应用程序中的 Cloud Speech-To-Text 客户端身份验证,我使用以下内容:
$credentials = 'C:cred.json';
$client=new SpeechClient(['credentials'=>json_decode(file_get_contents($credentials), true)]);
由于某些原因,我收到错误消息:
致命错误:未捕获的 GuzzleHttpExceptionClientException:客户端错误:
POST https://oauth2.googleapis.com/token导致400 Bad Request响应:{"error":"invalid_scope","error_description":"提供的 OAuth 范围或 ID 令牌受众无效。"}
上述身份验证方法在 Text-To-Speech API 中完美运行。
$credentials = 'C:cred.json';
$client = new TextToSpeechClient(['credentials' => json_decode(file_get_contents($credentials), true)]);
有什么问题/缺失?
回答
通过更新 Auth 模块(在 Vendor 文件夹中)解决的问题。只需在 composer.json 文件中将您的 Auth 版本更改为最新版本。
{
"require": {
"google/auth": "1.14.3",
"google/cloud-text-to-speech": "^0.5.0",
"google/cloud-speech": "^1.3",
"google/protobuf": "^3.14",
"phpmailer/phpmailer": "^6.1",
"google/apiclient": "2.5"
}
}
一旦完成,我就跑
作曲家更新
在相应目录中的命令行中。现在它起作用了。
-
This saved my day!
I rather not add sub-dependencies to my composer or run `composer update` which would update all other libraries as well.Running `composer update google/cloud-text-to-speech --with-dependencies` worked fine as well. Alternatively you could run `composer show` and check which dependencies you may need updating (in my case it worked if I updated "google/auth","google/gax" and "google/cloud-core")
THE END
二维码