-1

我想從存儲在谷歌雲存儲谷歌Play分析數據。經過調查發現,Google Play Analytics報告數據沒有直接API。 因此,我發現Access Google play account reports through Google API Client PHP Library鏈接,並遵循相同的給定。我已經創建了服務帳戶,獲得了所有者的許可,並啓用了Google雲API。如何解決403被禁止訪問存儲桶谷歌雲存儲

在鏈接中顯示的代碼中,我收到垃圾數據,如果我var_dump($桶),並且如果運行進一步的代碼,我得到這個錯誤。

Fatal error: Uncaught exception 'Google\Cloud\Exception\ServiceException' with message '{ "error": { "errors": [ { "domain": "global", "reason": "forbidden", "message": "Caller does not have storage.objects.list access to bucket I cannot show any JS fiddle as the bucket name and other information like key is confidential to company. Here is code i used,

require 'vendor/autoload.php'; 
use Google\Cloud\Storage\StorageClient; 
$client = new StorageClient([ 'projectId'=> 'myproject-id','scopes'=> [StorageClient::READ_ONLY_SCOPE],'keyFile'=> json_decode(file_get_contents('path_to_jsonfile'), true) ]);         $bucket=$client->bucket('mybucketname'); 
/*Find bucket name in Google Developer Console>>Reports */ 
$buckets=$client->buckets([ 'prefix' => 'stats/installs/']); 
foreach ($buckets as $bucket) {echo $bucket->name().PHP_EOL; } 

接受一些幫助。請告訴我一些解決方案。在此先感謝

+0

我想你應該檢查你的代碼的第153行。我們無法幫助您查看您的代碼。 – DaImTo

+0

根據[試圖訪問雲存儲的設備](https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow),身份驗證要求可能會有所不同。這段代碼在哪裏運行?是否所有的存儲桶名稱都以['stats/installs /'前綴]開頭(https://googlecloudplatform.github.io/google-cloud-php/#/docs/google-cloud/v0.24.0/storage/storageclient?方法=桶)? – Nicholas

回答

1

事實上,需要更多關於代碼結構的詳細信息,才能提供一個明確的解決方案,如上述評論所述。如果我們查看「Google \ Cloud \ Storage \ StorageClient」文檔page,即以下列行開頭的行,則可能是您的應用可能跳過了需要的階段:使用Google \ Cloud \ ServiceBuilder; 。

此外,存儲在JSON中的憑據可能不正確。您是否通過gcloud auth login命令在實例上創建了憑據?

+0

Credentails被創建爲服務帳戶,json代碼被複制到文件中,路徑在代碼中給出。還有什麼要做的嗎? – Pratima

+0

這些應該足夠了。 keyFilePath是否正確?它是一個字符串:「從Google Developers Console檢索到的服務帳戶憑證.json文件的完整路徑」。 – George