【发布时间】:2017-02-28 13:27:23
【问题描述】:
我想从存储在 Google Cloud Storage 中的 Google Play Analytics 中获取数据。经过大量研究发现,没有直接的 API 来获取 Google Play Analytics 报告数据。 因此,我找到了Access Google play account reports through Google API Client PHP Library 链接并遵循相同的给定。我已经创建了服务帐户,授予了所有者权限,并且也启用了谷歌云 API。
在链接中显示的代码中,如果我是 var_dump($bucket),我会得到垃圾数据,如果运行进一步的代码,我会收到此错误。
致命错误:未捕获的异常 'Google\Cloud\Exception\ServiceException' 带有消息 '{ "error": { "errors": [ { "domain": "global", "reason": "forbidden", "message ": "调用者没有存储桶的 storage.objects.list 访问权限 我无法显示任何 JS 小提琴,因为存储桶名称和其他信息(如密钥)对公司来说是机密的。 这是我使用的代码,
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; }
接受一些帮助。请告诉我一些解决方案。提前致谢
【问题讨论】:
-
我认为您应该检查代码的第 153 行。我们无法帮助您查看您的代码。
-
身份验证要求可能因what device is attempting to reach Cloud Storage 而异。这段代码在哪里运行?您所有的存储桶名称都以
stats/installs/prefix 开头吗?
标签: php google-cloud-storage google-play-developer-api