2016-12-15 129 views
0

我是使用google API的新手。我正在嘗試使用谷歌語音識別,將我的語音轉換爲文本,反之亦然。但不知道如何使用谷歌語音API。我使用這個命令下載谷歌雲包如何使用谷歌雲語音API

composer require google/cloud 

但我不知道如何使用這個。我從這個鏈接繼續教程https://github.com/GoogleCloudPlatform/google-cloud-php。 但它顯示我的錯誤。

Fatal error: Uncaught Google\Cloud\Exception\ServiceException: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information in /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php:221 
Stack trace: 

#0 /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php(185): Google\Cloud\RequestWrapper->convertToGoogleException(Object(DomainException)) 
#1 /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php(167): Google\Cloud\RequestWrapper->fetchCredentials() 
#2 /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php(150): Google\Cloud\RequestWrapper->getToken() 
#3 /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php(131): Google\Cloud\RequestWrapper->signRequest(Object(GuzzleHttp\Psr7\Request)) 
#4 /var/www/html/googlevoice/vendor/google/cloud/src/RestTrait.php(78): Google\Cloud\RequestWrapper->send(Object(GuzzleHttp\Psr7\Request), Array) 
#5 /var/www/html/googlevoice/vendor/goo in /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php on line 221 
+0

當你按照給出的鏈接後會發生什麼給你留言本身? ---> https://developers.google.com/accounts/docs/application-default-credentials – DaImTo

+0

我沒有收到任何東西。我剛剛得到上述錯誤。 –

+0

再次創建憑證教程。你的代碼不能讀取它。 – DaImTo

回答

0

首先看起來您需要生成服務帳戶憑據:)。

請看看這個指南,以獲得該設置:https://googlecloudplatform.github.io/google-cloud-php/#/docs/latest/guides/authentication

從那裏,你要做到以下幾點:

require 'vendor/autoload.php'; 

use Google\Cloud\Storage\StorageClient; 

// Pass the key file directly into your client. 
$storage = new StorageClient([ 
    'keyFilePath' => '/path/to/service/credentials.json' 
]); 

// OR 

// Store the key file as an environment variable 
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/credentials.json'); 

$storage = new StorageClient(); 
+0

感謝David S回覆 –

+0

我啓用了所提供的鏈接上提供的所有API。但在此之後,我收到錯誤致命錯誤:Uncaught Google \ Cloud \ Exception \ ServiceException:{ 「error」:「deleted_client」, 「error_description」:「OAuth客戶端已被刪除。 } in /var/www/html/googlevoice/vendor/google/cloud/src/RequestWrapper.php:219 –

+0

有趣!如果您還沒有嘗試過,我建議重新生成您的服務帳戶憑據。如果這不起作用,我會直接與支持團隊聯繫 - https://cloud.google.com/support/ –