Daniel Stark
Daniel Stark

Reputation: 57

Google Indexing API

I have a job portal website (Wordpress + PHP) and I want using Google Indexing API for my website. I don't have any experience on GoogleAPI so I just read their guidance. According to the guide, to use the Indexing API it has 3 steps:

  1. Complete the prerequisites by enabling the Indexing API, creating a new service account, and verifying ownership in Search Console.
  2. Get an access token to authenticate your API call.
  3. Send requests to notify Google of new, updated, or deleted web pages.

I completed the step 1 but step 2 and 3 it really confuse me. Seem like I need obtain the OAuth token with coding but where do I put these code ? For using API, they show me this example :

POST https://indexing.googleapis.com/v3/urlNotifications:publish
{
  "url": "https://careers.google.com/jobs/google/technical-writer",
  "type": "URL_UPDATED"
}

Again, Im not sure where do I put these block code to using API. Can anyone know about this can explain step by step how to do it for me? Last question : because my website get around 10 - 15 new job post per day. Can I somehow set this Indexing API automatic send request to Google whenever someone post a new job ? Regards,

Upvotes: 1

Views: 9190

Answers (5)

Hireme1st
Hireme1st

Reputation: 7

The simple answer is just to install the Rankmath Indexing API plugin. After adding the owner as Ruha Thai explain above - upload the JSON code to the plugin settings and that's it.

Upvotes: -2

user3158087
user3158087

Reputation: 1

Rank Math just released free Indexing plugin for WordPress, you can give it a try, it does all the things automatically. More details: https://rankmath.com/blog/google-indexing-api/

Upvotes: -3

Activate Google Indexing API: https://console.developers.google.com/apis/library/indexing.googleapis.com

In PHP you find more Information about the Error with:

$body = $response->getBody();
$stringBody = (string) $body;

Upvotes: 1

Rua Tahi
Rua Tahi

Reputation: 258

You must sure verify site ownership in Search Console : https://www.google.com/webmasters/tools/home

  1. Click your verified property.
  2. Select Verification details from the Settings gear next to your verified property.
  3. Under Verified owners, click Add an owner.
  4. Add your service account email address as an owner to the property.

You can confirm your service account like my-service-account@project-name.google.com.iam.gserviceaccount.com

enter image description here

Upvotes: 1

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116968

You should be passing it as a Bearer authentication Header in your request.

Authorization: Bearer

You may also be able to pass it as part as a request string I cant remember if this works with post calls though.

POST https://indexing.googleapis.com/v3/urlNotifications:publish?Access_token=XXXX
{
  "url": "https://careers.google.com/jobs/google/technical-writer",
  "type": "URL_UPDATED"
}

If you are using php you should consider using the Google php client library which will handle most of this for you. which is what they recommend in the example here

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();

Make sure you have set up the service account properly create service account

Upvotes: 4

Related Questions