douduidui1046 2016-06-13 12:38
浏览 20

Analytics API和PHP - 以不同格式获取报告

The following code returns an object of Google_Service_AnalyticsReporting_GetReportsResponse

$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests($aRequests);
return $this->oAnalytics->reports->batchGet($body);

I'm wondering if I can get Reports in a different format, example: Array(Dimension,value)

  • 写回答

2条回答 默认 最新

  • doupu0619 2016-06-24 12:54
    关注

    Yes.

    The Google Reporting v4 SDK for PHP looks like it has been automatically converted from java code, right along with all the usual object overkill.

    To convert to an array, assuming you asked for one dimension and some metrics:

    $data = []
    foreach ($this->oAnalytics->reports->batchGet($body)->getReports()[0]->getData()->getRows() as $row) {
      $key = $row->dimensions[0]; // chose a unique value or dimension that works for your app, or remove and use $data[] = $value; below
      $values = array_merge($row->metrics, $row->dimensions);    
      $data[$key] = $value;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度