Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Indexing API - 403 'Forbidden Response'

I am making a call to the google indexing API for job postings:

private $client;
private $httpClient;

public function initClient($kernel)
{
    $this->client = new \Google_Client();
    $this->client->setAuthConfig(JSON_KEY_HERE);
    $this->client->addScope('https://www.googleapis.com/auth/indexing');
    $this->httpClient = $this->client->authorize();
}

public function sendJob()
{
    $endpoint = 'https://indexing.googleapis.com/v3/urlNotifications:publish';
    $content = "{
                    \"url\": \"URL_HERE\",
                    \"type\": \"URL_UPDATED\"
                }";

    $response = $this->httpClient->post($endpoint, array('body' => $content));
}

When making the call to the API, the response given is '403 - Forbidden' .

Any ideas what this error actually means? I have created the service account correctly but cannot replicate success from my dev enviroment.

like image 708
Joe Saunderson Avatar asked Jul 19 '18 15:07

Joe Saunderson


1 Answers

After couple days of headache, here is the answer. Open your Google search console.

Prerequisite: You must already have a google service account

click the tri dot button, and click manage property owners:

click the tri dot button, and click manage property owners

add google service account email as new owners:

add google service account email as new owners

like image 148
kopi Avatar answered Oct 06 '22 12:10

kopi