K
K
Konstantin Mazurov2016-11-01 09:17:16
Google
Konstantin Mazurov, 2016-11-01 09:17:16

How to work with Google Webmasters using a service key?

Hey! I use the official php client from Google and it seems that something is even connected, but I can’t understand whether it works at all or not.
The task of cron to pull data from the search api is a summary of the data, for this I created a Project, a Service key ( https://console.developers.google.com/flows/enable... , downloaded it and connected it as requested. Don't be scared, this is a Laravel controller, but what framework doesn't matter..

$key_file_location = base_path() . Config::get('google.key_file_location');
        putenv('GOOGLE_APPLICATION_CREDENTIALS='.$key_file_location);
        $this->client = new \Google_Client();
        $this->client->useApplicationDefaultCredentials();
        $this->client->setApplicationName("HelloAnalytics");

        $this->client->setScopes([\Google_Service_Webmasters::WEBMASTERS_READONLY]);
        $this->service = new \Google_Service_Webmasters($this->client);
               $key_file_location = base_path() . Config::get('google.key_file_location');
        putenv('GOOGLE_APPLICATION_CREDENTIALS='.$key_file_location);
        $this->client = new \Google_Client();
        $this->client->useApplicationDefaultCredentials();
        $this->client->setApplicationName("HelloAnalytics");

        $this->client->setScopes([\Google_Service_Webmasters::WEBMASTERS_READONLY]);
        $this->service = new \Google_Service_Webmasters($this->client);
        $results = $this->service->sites->get('http://test.ru/'); // <----- тут ссылка на сайт который есть в кабинете вебмастера гугла и права на него подтверждены(либо подтверждены, как-то криво).

The answer comes:
{ "error": { "errors": [ { "domain": "global", "reason": "notFound", "message": "'http:// test.ru /' is not a verified Search Console site in this account.", "locationType": "parameter", "location": "siteUrl" } ], "code": 404, "message": "'http:// test.ru /' is not a verified Search Console site in this account." } }

If I request a list of all sites, then nothing comes up at all, although there are more than 100 client sites in my account ...
Or do I need to log in via oAuth2?
I don't know what to do, please help :)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question