【发布时间】:2019-06-13 10:25:06
【问题描述】:
我正在尝试在我的 Laravel 项目中使用 Google Translate API。我跟着这个教程https://cloud.google.com/translate/docs/quickstart-client-libraries?authuser=2#client-libraries-install-php
但是当我尝试运行代码进行翻译时,我得到了这个错误 -
Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/. To disable this warning, set SUPPRESS_GCLOUD_CREDS_WARNING environment variable to "true".
这是我的代码:
public static function gcloud(){
# Your Google Cloud Platform project ID
$projectId = 'mybot';
# Instantiates a client
$translate = new TranslateClient([
'projectId' => $projectId
]);
# The text to translate
$text = 'Hello, world!';
# The target language
$target = 'ru';
# Translates some text into Russian
$translation = $translate->translate($text, [
'target' => $target
]);
echo 'Text: ' . $text . '
Translation: ' . $translation['text'];
}
我不知道可能是什么问题。
【问题讨论】:
标签: php laravel google-api google-translate