Based on schulzefelix/laravel-search-console and modified to Laravel 8
Using this package you can easily retrieve data from Google Search Console API.
Here are a few examples of the provided methods:
This package can be installed through Composer.
$ composer require tda/laravel-search-console
Here are two basic example to retrieve all sites and an export for search analytics data.
use Tda\GoogleSearchConsole\SearchConsole;
$searchConsole = new SearchConsole();
$sites = $searchConsole->setAccessToken($this->token)->listSites();
//get site details (permissionLevel) for specific site
$site = $searchConsole->setAccessToken($token)->getSite('http://blog.example.com/');
use Tda\GoogleSearchConsole\SearchConsole;
use Tda\SearchConsole\Period;
$searchConsole = new SearchConsole();
$data = $searchConsole->setAccessToken($this->token)->setQuotaUser('uniqueQuotaUserString')
->searchAnalyticsQuery(
'https://www.example.com/',
Period::create(Carbon::now()->subDays(30), Carbon::now()->subDays(2)),
['query', 'page', 'country', 'device', 'date'],
[['dimension' => 'query', 'operator' => 'notContains', 'expression' => 'cheesecake']],
1000,
'web',
'all',
'auto'
);
public function public function getSite(string $siteUrl): array
public function public function listSites(): Collection
public function searchAnalyticsQuery(string $siteUrl, Period $period, array $dimensions = [], array $filters = [], int $rows = 1000, string $searchType = 'web', string $dataState = 'final', string $aggregationType = 'auto'): Collection
public function public function isAccessTokenExpired(): Bool
To avoid to the API limits, you can provide a unique string for the authenticated account.
More information: https://developers.google.com/webmaster-tools/search-console-api-original/v3/limits
$sites = SearchConsole::setAccessToken($token)->setQuotaUser('uniqueQuotaUserString')->listSites();
You can get access to the underlying Google_Service_Webmasters
object:
SearchConsole::getWebmastersService();
Please see CHANGELOG for more information what has changed recently.
$ vendor/bin/phpunit
Please see CONTRIBUTING and CONDUCT for details.
The MIT License (MIT). Please see License File for more information.