如何强制数组显示所有值?

时间:2012-11-06 03:21:50

标签: php arrays google-analytics-api

我的数组的输出在print_r($ segments)之后看起来与此类似:

Array
(
    [kind] => analytics#segments
    [username] => account@gmail.com
    [totalResults] => 2334
    [startIndex] => 1
    [itemsPerPage] => 1000
    [items] => Array
    (
        [0] => Array
            (
                [id] => -1
                [kind] => analytics#segment
                [selfLink] => https://www.googleapis.com/analytics/v3/management/segments/gaid::-1
                [segmentId] => gaid::-1
                [name] => All Visits
                [definition] => 
            )
...

        [999] => Array
            (
                [id] => -1
                [kind] => analytics#segment
                [selfLink] => https://www.googleapis.com/analytics/v3/management/segments/gaid::-1
                [segmentId] => gaid::-1
                [name] => All Visits
                [definition] => 
            )
    )
)

此数组是来自Google Analytics(分析)API PHP的输出,它显示的最大值是 1000 行,如 itemsPerPage 参数,但我确实有超过1000,接近 2334 ,如 totalResults 参数。

有人知道如何强制它一次显示所有输出吗?

当我运行时:

 $nextLink = $results->getNextLink()
            ? $results->getNextLink() : 'none';

print($nextLink);

输出是链接https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties/~all/profiles?start-index=1001&max-results=1000

Accoring to this documentation I have to use the parameter called 最高结果 to display more results per page, but I have no idea how to do so, no much documentation about it.

知道如何使用 max-results 参数或链接获取其余结果?

1 个答案:

答案 0 :(得分:3)

快速回答https://developers.google.com/analytics/devguides/reporting/core/v3/coreDevguide#working

查看分页信息,您的数据似乎应该有getNextLink()getPreviousLink(),这可能不是数据的一部分,也不会打印在{ {1}}。

通过网络访问API,而不知道API需要返回多少信息时,您不希望冒险一次性发送大量数据。这可能会导致大量不必要的流量,并降低整个系统的速度。

一个解决方案,Pagination,是发回一定数量的响应(在这种情况下为1000),如果API的用户需要更多,请让他们明确请求下一组。

Psuedo代码: (抱歉,我没有可用的Google-API设置来尝试此操作)

print_r()