I am trying to integrate google index API with my website in order to index my side but i am getting 401 error. I searched and got this solution for my problem. Google Indexing API - 403 'Forbidden Response' But this is also not working in my case since i have verified that i am owner in google search console plus integrating right JSON authentication file. I am checking index matrics but and getting all number of calls in my console platform.
require_once 'google-api-php-client/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",
"type": "URL_UPDATED"
}';
$response = $httpClient->post($endpoint, [ 'body' => $content ]);
$status_code = $response->getStatusCode();
any help will be appreciated. Thank in advance