-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