dongluo8439 2015-04-07 15:41
浏览 42
已采纳

PHP上的Google AnalyticsAPI

But still I got this issue:

Fatal error: Uncaught exception 'Google_Exception' with message '(get) missing required param: 'ids'' in /home/sample/www/test/google-api-php-client-master/src/Google/Service/Resource.php:163 Stack trace: #0 /home/sample/www/test/google-api-php-client-master/src/Google/Service/Analytics.php(2107): Google_Service_Resource->call('get', Array, 'Google_Service_...') #1 /home/sample/www/test/google-api-php-client-master/practicein.php(57): Google_Service_Analytics_DataRealtime_Resource->get('ga:********', 'ga:pageviews', '2015-03-07', '2015-04-04') #2 /home/sample/www/test/index.php(34): require_once('/home/lanforest...') #3 {main} thrown in /home/sample/www/test/google-api-php-client-master/src/Google/Service/Resource.php on line 163

And I think the codes around here is wrong.

$results = $analytics->data_realtime->get(
    $analytics_view_id,
    'ga:pageviews',//**I did correct this.**
    '2015-03-07',
    '2015-04-04'
);

//**I think these goes wrong**
$totals = $results->getTotalsForAllResults();
$array = array("activeUsers" => $totals["rt:activeUsers"]);

I want to see just page views. What can I code?

I think I got active user value.But,It still warning. What kind of error is this?

Warning: Cannot modify header information - headers already sent by (output started at /home/sample/www/test/index.php:16) in /home/sample/www/test/google-api-php-client-master/practicein.php on line 76

Warning: Cannot modify header information - headers already sent by (output started at /home/sample/www/test/index.php:16) in /home/sample/www/test/google-api-php-client-master/practicein.php on line 77

{"activeUsers":"0"}//this is the result.
  • 写回答

1条回答 默认 最新

  • dongyu4554 2015-04-07 16:05
    关注

    From your starcktrace i see:

    #1 .../practicein.php(66): Google_Service_Analytics_DataRealtime_Resource->get('ga:*******', '2015-03-07', '2015-04-04', 'ga:pageviews'
    

    You are calling the get method with wrong params: first one is your ga id, the second one must be metrics, then you can pass opt params.

    Check the get method docs in src/Google/Service/Analytics.php:

    /**
     * Returns real time data for a view (profile). (realtime.get)
     *
     * @param string $ids Unique table ID for retrieving real time data. Table ID is
     * of the form ga:XXXX, where XXXX is the Analytics view (profile) ID.
     * @param string $metrics A comma-separated list of real time metrics. E.g.,
     * 'rt:activeUsers'. At least one metric must be specified.
     * @param array $optParams Optional parameters.
     *
     * @opt_param int max-results The maximum number of entries to include in this
     * feed.
     * @opt_param string sort A comma-separated list of dimensions or metrics that
     * determine the sort order for real time data.
     * @opt_param string dimensions A comma-separated list of real time dimensions.
     * E.g., 'rt:medium,rt:city'.
     * @opt_param string filters A comma-separated list of dimension or metric
     * filters to be applied to real time data.
     * @return Google_Service_Analytics_RealtimeData
     */
     public function get($ids, $metrics, $optParams = array())
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c