Reputation: 57
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:
- Complete the prerequisites by enabling the Indexing API, creating a new service account, and verifying ownership in Search Console.
- Get an access token to authenticate your API call.
- 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
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
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
Reputation: 607
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
Reputation: 258
You must sure verify site ownership in Search Console : https://www.google.com/webmasters/tools/home
You can confirm your service account like my-service-account@project-name.google.com.iam.gserviceaccount.com
Upvotes: 1
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