1

在這裏我得到了一個和上一個網址,但試圖與URL訪問下一個頁面時,我得到錯誤的分頁在谷歌分析報告

URL = 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

Error: {"error":{"errors":[{"domain":"global","reason":"required","message":"Login Required","locationType":"header","location":"Authorization"}],"code":401,"message":"Login Required"}}

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; 
     } 

我也想知道當前頁碼,有沒有任何功能?

+0

[Google analytics API分頁當前頁碼和下一頁認證]的可能重複(http://stackoverflow.com/questions/34089788/google-analytics-api-pagination-current-page-number-and-nextpage-authentication ) –

回答

0

您需要添加accesss_token參數:&access_token=ya29.AKDF.....您應該能夠從您的授權客戶端對象得到它:

$token = $client->getAccessToken(); 

然後此令牌附加到下一個頁面的鏈接。

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

然後鏈接應該被認證。

+0

您仍然需要將訪問令牌添加到下一個和上一個鏈接。 – Matt

+0

我試着通過'$ this-> results-> getPreviousLink()。 '&的access_token ='。 $ _SESSION ['access_token']'但不工作。 –