PHP - Google APİ ile Web Master Veriler Çekmek.

14 dakika okuma süresi

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/

Ofislerimiz

Drupart AR-GE

GOSB Teknopark Hi-Tech Bina 3.Kat
B3 Gebze - KOCAELİ

+90 262 678 8872 

[email protected]

Drupart Frankfurt

Media4People Bleichstr. 26 64283 Darmstadt
Deutschland

+49 (0) 6151 – 492 70 23 

[email protected]

Drupart Dublin

20 Harcourt Street, Dublin 2, D02 H364

+353 (87) 198 6950 

[email protected]