I want to execute on "Google Indexing API" Code.
<?php
require_once 'google-api-php-client-2.2.2/vendor/autoload.php';
$client = new Google_Client();
// service_account_file.json is the private key that you created for your service account.
$client->setAuthConfig('service_account_file.json');
$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.html\",
\"type\": \"URL_UPDATED"
}';
$response = $httpClient->post($endpoint, [ 'body' => $content ]);
$status_code = $response->getStatusCode();
echo $status_code;
?>
But in response, I get an error: 403.
I created on service account and Site Verification is complete
I want to add on service account email address in the Google Search Console.
what is the issue in our code?
Appreciate any help and ideas. Thanks!