1- İlk önce kimlik bilgileri aşağıdaki gibi oluşturacak. link -> https://console.developers.google.com/apis/credentials
2- Doğrulandıktan sonra php ile kodlandığı sayfasına GET ile dönebilecek 'Yetkilendirilmiş yönlendirme URI'ları' kısmındaydı. Ancak birden fazla ekleyebilirsiniz.
3- Kimlik bilgileri oluşturdu. Ve Google Api için php kütüphane kaynak https://github.com/google/google-api-php-client
4- Kimlik bilgileri JSON dosyası indirip ana klasöre ekleyelim.
5 - php ile kodlanmış sayfa
session_start();
include_once 'vendor/autoload.php';
$redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$client = new Google_Client();
$client->setAuthConfig('oauth-credentials.json');
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/webmasters.readonly");
$service = new Google_Service_Webmasters($client);
if (isset($_GET['code'])) {
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
$client->setAccessToken($token);
$_SESSION['token'] = $token;
header('Location: '.filter_var($redirect_uri,FILTER_SANITIZE_URL));
}
if (!empty($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
if ($client->isAccessTokenExpired()) {
unset($_SESSION['token']);
}
} else {
$authUrl = $client->createAuthUrl();
}
if ($client->getAccessToken()) {
//SearchAnalyticsQuery
$fromDate = date('Y-m-d', strtotime('-3 months'));
$toDate = date('Y-m-d', strtotime('-1 day'));
$q = new \Google_Service_Webmasters_SearchAnalyticsQueryRequest();
$q->setStartDate($fromDate);
$q->setEndDate($toDate);
$q->setDimensions(['page']);
$u = $service->searchanalytics->query('http://neoola.com/', $q);
print_r($u);
//sitemaps.list
$listSitemaps = $service->sitemaps->listSitemaps('http://neoola.com/');
print_r($listSitemaps);
//sitemaps.get
$sitemaps_get = $service->sitemaps->get('http://neoola.com/', 'http://neoola.com/sitemap.xml');
print_r($sitemaps_get);
//sites.list
$listSites = $service->sites->listSites();
print_r($listSites);
//sites.get
$sites_get = $service->sites->get('http://neoola.com/');
print_r($sites_get);
//urlcrawlerrorscounts.query
$category = 'notFound';
$platform = 'web';
$urlcrawlerrorscounts_query = $service->urlcrawlerrorssamples->listUrlcrawlerrorssamples('http://neoola.com/',$category,$platform);
print_r($urlcrawlerrorscounts_query);
//urlcrawlerrorssamples.get
$url = 'konser/gulsen-konser';
$category = 'notFound';
$platform = 'web';
$urlcrawlerrorssamples_get = $service->urlcrawlerrorssamples->get('http://neoola.com/',$url,$category,$platform);
}
if (isset($authUrl))
echo 'Bağlan';
Ve bu kadar. Fonksiyonlar detaylı bilgiler görebilmek için linkte https://developers.google.com/apis-explorer/#search/console%20search/webmasters/v3/