谷歌分析报告中的分页

时间:2015-12-02 17:16:37

标签: php wordpress google-analytics google-analytics-api google-api-client

我在这里获取下一个和上一个网址,但在尝试使用网址访问下一个网页时,我收到错误

网址= https://www.googleapis.com/analytics/v3/data/ga?ids=ga:85914642&dimensions=ga:pagePath,ga:date&metrics=ga:pageviews,ga:uniquePageviews,ga:sessionDuration,ga:bounceRate,ga:exits&sort=-ga:pageViews&filters=ga:pageViews%3C%3D10&start-date=7daysAgo&end-date=today&start-index=11&max-results=10

  

错误:   { “错误”:{ “错误”:[{ “域”: “全局”, “原因”: “需要”, “消息”:“登录   需要 “ ”的locationType“: ”首部“, ”位置“: ”授权“}], ”代码“:401, ”消息“:” 登录   必需“}}

  public  function getPaginationInfo(&$results) {
        $client = new Google_Client();
        if( isset( $_SESSION['access_token'] ) ){
            $client->setAccessToken($_SESSION['access_token']);
        } 
        // Create an authorized analytics service object.
        $analytics = new Google_Service_Analytics($client);

        // Get the first view (profile) id for the authorized user.
        $profile = $this->getFirstProfileId($analytics);

        // Get the results from the Core Reporting API and print the results.
        $this->results = $this->getResults($analytics, $profile);
        var_dump( $this->results );

        $html = <<<HTML
        <pre>
        Items per page = {$this->results->getItemsPerPage()}
        Total results  = {$this->results->getTotalResults()}
        Previous Link  = {$this->results->getPreviousLink()}
        Next Link      = {$this->results->getNextLink()}
       </pre>
HTML; 

           print $html;
        }

我也想知道当前的页码,是否有任何功能?

1 个答案:

答案 0 :(得分:0)

您需要添加accesss_token参数:&access_token=ya29.AKDF.....您应该可以从授权的客户端对象中获取它:

$token = $client->getAccessToken();

然后将此令牌附加到您的下一页链接。

$this->results->getPreviousLink() . "&access_token=" . $token

然后应该对链接进行身份验证。

相关问题