WP Punk
WP Punk

Reputation: 1444

Indexing API 403 Permission denied. Failed to verify the URL ownership

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.".

  1. I created service account and read the file in my application.
  2. Site verified. screeen1
  3. Access to service account is full. screeen2
  4. I used domain without "www" and https in search console and in my app.
  5. Indexing API enabled and requests come.

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

Answers (2)

Rodrigo R. Coelho
Rodrigo R. Coelho

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

WP Punk
WP Punk

Reputation: 1444

Full access !== Owner. I need to read the documentation better.

Upvotes: 3

Related Questions