Access Google play account reports through Google API Client PHP Library(通过 Google API 客户端 PHP 库访问 Google Play 帐户报告)
问题描述
- Google Play 开发者帐户报告存储在私有 Google Cloud Storage 存储分区中.
- 我想用 PHP 以编程方式下载这些报告.
- 在此链接部分-> 下载使用客户端库和报告服务帐户为此提供步骤.
- 但我仍然无法实现它.
- 也没有可用于 PHP 的示例代码,因为 Google API 客户端 PHP 库仍处于测试版.
- Google Play Developer Account reports are stored on private Google Cloud Storage bucket.
- I want to download these reports programmatically in PHP.
- In this link section-> Download reports using a client library & service account provide steps for that.
- But I am not able to achieve it still.
- Also no sample code is available for PHP, as Google API Client PHP Library are still in beta version.
那么真的有可能在 PHP 中访问私有的 Google Cloud Storage 存储桶吗?
So is it really possible to get access to private Google Cloud Storage bucket in PHP ?
我已经尝试过使用 gsutil 工具,但这并不能完全满足我的需要.
I have already tried out with gsutil tool, but that doesn't exactly satisfy my need.
我们将不胜感激.
推荐答案
首先,您必须创建一个用于身份验证的应用程序帐户.转到页面底部的 Google Play 开发者控制台 >> 设置 >> API 访问创建帐户"(不是 OAuth).然后为创建的帐户设置权限并以 JSON 格式生成密钥文件.应该是这样的:
At first you must create an Application Account that you will use for authentication. Go to Google Play Developer Console >> Settings >> API Access at the bottom of page click "Create Account" (not OAuth). Then set permissions for created account and generate key file in JSON. Should look like this:
{
"type": "service_account",
"project_id": "api-...",
"private_key_id": "...",
"private_key": "-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----
",
"client_email": "...@...iam.gserviceaccount.com",
"client_id": "...",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/..."
}
下一步在您的 PHP 脚本中使用生成的凭据.在 Composer Google Cloud 客户端库中下载或要求.
Next step use generated credentials in your PHP script. Download or require in Composer Google Cloud Client Library.
使用 Google Cloud 客户端库方法授权和下载报告文件:
Use Google Cloud Client Library methods to authorize and download report files:
use GoogleCloudStorageStorageClient;
$client = new StorageClient([
'scopes' => [StorageClient::READ_ONLY_SCOPE],
'keyFile' => json_decode(file_get_contents('yourKeyFile.json'), true)
]);
$bucket = $client->bucket('pubsite_prod_rev_*'); //Find your bucket name in Google Developer Console >> Reports
//List all objects in bucket
foreach ($bucket->objects(['prefix' => 'stats/installs/']) as $object) {
print_r($object->name());
}
//Download some file
$file = $bucket->object('stats/installs/installs_*_overview.csv');
$file->downloadToFile();
//Or print as string
echo $file->downloadAsString();
这篇关于通过 Google API 客户端 PHP 库访问 Google Play 帐户报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过 Google API 客户端 PHP 库访问 Google Play 帐户报告
基础教程推荐
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01