Google Search Console API仅返回1页

时间:2017-10-26 08:56:48

标签: php laravel google-api google-search-console

我正在查询Google Search Console API,当我将尺寸设置为页面时,我只返回一页?

$client = new Google_Client();
$client->setAuthConfigFile(base_path().'/client_id.json');
$client->setAccessToken($account->user_token);
$client->addScope(Google_Service_Webmasters::WEBMASTERS_READONLY);
$webmaster = new Google_Service_Webmasters($client);
$url = $account->console_url;
$options = [];

try{
    $search = new Google_Service_Webmasters_SearchAnalyticsQueryRequest;
    $search->setStartDate( date('Y-m-d', strtotime('-28 days')) );
    $search->setEndDate( date('Y-m-d', strtotime('-1 day')) );
    $search->setDimensions( ['page'] );
    $search->setAggregationType( 'auto' );

    $data = $webmaster->searchanalytics->query( $url, $search, $options )->getRows();

    dd($data);

}catch(\Exception $e){ 
    dd($e);
}

我得到的回应是;

array:1 [▼
  0 => Google_Service_Webmasters_ApiDataRow {#609 ▼
    #collection_key: "keys"
    #internal_gapi_mappings: []
    +clicks: 169.0
    +ctr: 0.0451992511367
    +impressions: 3739.0
    +keys: array:1 [▶]
    +position: 5.35758224124
    #modelData: []
    #processed: []
  }
]

有谁知道如何获取所有页面?或至少5000限制。

1 个答案:

答案 0 :(得分:0)

尝试改变这一点:

$search->setAggregationType( 'auto' );

到此:

$search->setAggregationType( 'byPage' );