google-search-consolegoogle-search-api

Rows data before 3-4 days are empty


I use Service Account and their credentials for fetching rows and everything was good.

Now I get empty rows for last 3-4 days, but when I used 5 days before time range, I get data, but this old data-results.

I use PHP library recommended by Google.

use Carbon\Carbon;
use Google\Service\SearchConsole\SearchAnalyticsQueryRequest;
use Google_Client;
use Google\Service;
-------------------------------

$client = new Google_Client();
$client->setAuthConfig($authConfig);
$client->addScope('https://www.googleapis.com/auth/webmasters.readonly');

$datesRange = ['start' => Carbon::now()->subDays(3)->format('Y-m-d'),
            'end' => Carbon::now()->subDays(1)->format('Y-m-d')];

$searchConsole = new Service\SearchConsole($client);
$searchAnalyticsQueryRequest = new SearchAnalyticsQueryRequest();
$searchAnalyticsQueryRequest->setSearchType("Web");
$searchAnalyticsQueryRequest->setStartDate($datesRange['start']);
$searchAnalyticsQueryRequest->setEndDate($datesRange['end']);
$searchAnalyticsQueryRequest->setRowLimit($rowLimit);

$dimensions = ['page', 'device', 'country', 'query', 'date'];

$searchAnalyticsQueryRequest->setDimensions($dimensions);

$rowList = $searchConsole->searchanalytics->query('https://xxxx.xxx/', $searchAnalyticsQueryRequest)>getRows();

Solution

  • Thanks to Google Community I got useful answer. For recent data, I don't know how they check it - important to use additional parameter to Search Query request.

    $searchAnalyticsQueryRequest->setDataState('all');

    So adding it to request shows positive results for querying rows.