Hi I am trying to use Google indexing API. I used this tutorial - https://developers.google.com/search/apis/indexing-api/v3/prereqs
I used this php library - different branch - v1-master because I dont use composer so I had to use autoload.php https://github.com/googleapis/google-api-php-client/tree/master
Here is my code:
require_once($_SERVER["DOCUMENT_ROOT"] . '/assets/google-api-php-client/src/Google/autoload.php');
require_once($_SERVER["DOCUMENT_ROOT"] . '/assets/google-api-php-client/examples/templates/base.php');
$client = new Google_Client();
// service_account_file.json is the private key that you created for your service account.
$client->setAuthConfig($_SERVER["DOCUMENT_ROOT"] . '/assets/google-api-php-client/serviceAccount');
$client->addScope('https://www.googleapis.com/auth/indexing');
// Get a Guzzle HTTP Client
$httpClient = $client->authorize();
$endpoint = 'https://indexing.googleapis.com/v3/urlNotifications:publish';
// Define contents here. The structure of the content is described in the next step.
$content = '{
"url": "http://example.com/jobs/42",
"type": "URL_UPDATED"
}';
$response = $httpClient->post($endpoint, [ 'body' => $content ]);
$status_code = $response->getStatusCode();
- I created service account
- downloaded service account json file This is how the json looks
- added path to json as you can see above
- I enabled Indexing API in console.developers.google.com for my project
- json loads
But I got error Uncaught Google_Exception: Invalid client secret JSON file.
This topic is related to - google-api-php-client: Invalid client secret JSON file
But i just could not resolve it and I am stuck
question from:https://stackoverflow.com/questions/65945539/google-indexing-api-wrong-json-file