在项目中我们一直使用
google/cloud
包的SpeechClient。我现在正在将其升级到未弃用的 /V1/SpeechClient,但我遇到了以下错误
"Google\ApiCore\ApiException: {
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https:\/\/developers.google.com\/identity\/sign-in\/web\/devconsole-project.",
"code": 16,
"status": "UNAUTHENTICATED",
"details": []
}
此身份验证信息在以前的版本中有效,我尝试更改为它希望我进行身份验证的新方式,但我想我做得不正确。有什么帮助吗?
之前的设置:
// $auth is keyfile in an Array format. it matches the design given in here, with the edit fields filled
// https://cloud.google.com/iam/docs/keys-create-delete#iam-service-account-keys-create-console
$speech = new Google\Cloud\Speech\SpeechClient([
'keyFile' => $auth,
]);
升级版:
// $auth is the same as above
$creds = CredentialsWrapper::build([
'keyFile' => $auth
]);
// Create the speech client
$speech = new Google\Cloud\Speech\V1\SpeechClient([
'credentials' => $creds,
]);
...
$operation = $speech->longRunningRecognize(
$config,
$audio
);
// gives me output as normal
$operation->getName();
// throws exception at the top of the post
$operation->reload();
可能是应用程序默认凭据不可用。尝试通过运行 gcloud auth application-default login 来登录
并按照说明进行操作,参考:gcloud auth application-default login
如果您想确保身份验证过程顺利进行,请运行:gcloud auth application-default print-access-token
您应该看到一个访问令牌,参考 gcloud auth application-default print-access-token