Benjamin Goutfer Benjamin Goutfer - 1 year ago 71
PHP Question

Retrive stats app install Play Store Google API in PHP

I'm working on a back office feature it retrieve all monthly app installations stats. I'd like to use an API to automatize it. I'm currently looking for the Google API storage. I found that to get monthly reports :
They only explain how doing that in Python.
I don't have any idea to do that in PHP.

I wrote in a test_call.php file :

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

$client = new Google_Client();

I don't see how to proceed now.
Thanks for your answers.


Answer Source

I don't have much experience working with the Storage API; Nevertheless, if all you are looking for is an example of how to use the PHP Client library to get bucket objects (such as the monthly reports) then you might want to try using this code:

<?php session_start(); 

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

$scopes = array(

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

if (isset($_SESSION['access_token']) && $_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 {

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

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



Please note this implementation is not done with the use of a service account like how this document explains. If you would like to perform an implementation using a service account then please refer to this document.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download