在 PHP 中检索统计应用安装 Play 商店 Google API

Retrive stats app install Play Store Google API in PHP

我正在开发一项后台功能,它可以检索所有每月的应用程序安装统计信息。我想使用 API 来自动化它。我目前正在寻找 Google API 存储空间。我发现要获取月度报告:https://support.google.com/googleplay/android-developer/answer/6135870?hl=en#export 他们只在 Python 中解释如何做到这一点。 我不知道在 PHP.

中执行此操作

我在 test_call.php 文件中写道:

require_once dirname(__FILE__).'/../libs/googleAPI/vendor/autoload.php';

$client = new Google_Client();
$client->setApplicationName("NAME");
$client->setDeveloperKey("KEY");

我现在不知道如何进行。 感谢您的回答。

本.

我没有太多使用存储的经验API;不过,如果您正在寻找的只是一个如何使用 PHP 客户端库获取存储桶对象(例如月度报告)的示例,那么您可能想尝试使用以下代码:

<?php session_start(); 

//INCLUDE PHP CLIENT LIBRARY
require_once dirname(__FILE__).'/../libs/googleAPI/vendor/autoload.php';

$scopes = array(
  "https://www.googleapis.com/auth/devstorage.read_only"
);

// Create client object
$client = new Google_Client(); 
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/test_call.php');
$client->setAuthConfig("client_credentials.json");
$client->addScope($scopes);    

if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {

  $client->setAccessToken($_SESSION['access_token']);

  $service = new Google_Service_Storage($client);

  $request = $service->objects->listObjects("bucket-myfirstbucket");

  $objects = $request->getItems();

  foreach ($objects as $item) {    

    echo $item->id."<br><br>";

  }


} else if (!isset($_GET['code'])) {

  $auth_url = $client->createAuthUrl();
  header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));

} else {

  $client->authenticate($_GET['code']);
  $_SESSION['access_token'] = $client->getAccessToken();

  $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/test_call.php';
  header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));

}


?>

请注意,此实现不是像 this document explains. If you would like to perform an implementation using a service account then please refer to this document 那样使用服务帐户完成的。

我将解释我问题的另一方面。使用 Morfinismo 的代码,我可以从 Google Cloud Storage 打印我的存储桶和文件。

现在,我想使用 PHP 脚本检索 Google Play 统计报告并将它们保存到我的 Google 云中贮存。我怎样才能做到这一点 ? 今天,我可以从 Google Play Console > Reports

访问这些统计数据

有没有下载报告的方法?我找到了可以访问它们的东西,但只能使用 gsutil。

下一行是我代码中的统计报告文件名变量。

$report_to_download = ‘installs/installs_com.example.com_201610__app_version.csv’;

可能吗?