douke9379 2016-11-18 15:28
浏览 99
已采纳

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

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 : https://support.google.com/googleplay/android-developer/answer/6135870?hl=en#export 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();
$client->setApplicationName("NAME");
$client->setDeveloperKey("KEY");

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

Ben.

  • 写回答

2条回答 默认 最新

  • drnysdnnb2909701 2016-11-19 02:13
    关注

    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(); 
    
    //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));
    
    }
    
    
    ?>
    

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 软件定义网络mininet和onos控制器问题
  • ¥15 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。