Reputation: 1444
I want to execute the code from the example:
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\", //I used real url from my homepage
\"type\": \"URL_UPDATED\"
}";
$response = $httpClient->post($endpoint, [ 'body' => $content ]);
$status_code = $response->getStatusCode();
But in response, I get an error: 403 "Permission denied. Failed to verify the URL ownership.".
What else needs to be done and checked to gain access?
Answer
Full access !== Owner. I need to read the documentation better.
Upvotes: 6
Views: 3013
Reputation: 168
As mentioned, your service account should be "owner" (not "full"). With the new search console, it is almost impossible to set the service account to Owner, luckily, you can use the old Webmasters tool.
https://support.google.com/webmasters/thread/4763732?hl=en
Upvotes: 5