Answer the question
In order to leave comments, you need to log in
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/'); // <----- тут ссылка на сайт который есть в кабинете вебмастера гугла и права на него подтверждены(либо подтверждены, как-то криво).
{ "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." } }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question