How To Make Google Instantly Crawl Your Site and Increase its Visibility
Tags: googlecloud, webdev, api, php
Published: 2022-12-04 22:28:10

In this article, we'll look at how to directly notify Google of changes to the site and share our experience using the Google Indexing API with examples, to solve page indexing problems that prevent robots from getting up-to-date site information. 

## Overview
To address this issue, Google developers have created the Indexing API, which allows the Googlebot to check your pages before the sitemap is updated.

The Indexing API allows you to control actions such as:

- Update URL - when the page content has been updated.
- Remove URL - when the page no longer exists or is not available.
- Getting the status of the last indexation

> The quota for sending data to Google is 200 links/day, but you can also increase the quota.

## Benefits of using Indexing API
- Content actualization. This is very important when the information on the page changes frequently.
- Fast ranking of the site directly affects the search results and what position your site will take.

## Step-by-step instructions for setting up the Google Indexing API

On the example of one of our sites we'll show the algorithm of all actions to activate quick indexing of your site. Let's take [dogsrank.com](https://dogsrank.com) as an example.

### Project creation and API activation
1.Let's go to Google Cloud Platform and create a new project for our site.

![Creating a new Google Cloud Platform project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uqnh9jn2qgnd1rldtnqj.jpg)

2.Select the previously created project and activate the [Indexing API](https://console.cloud.google.com/apis/library/indexing.googleapis.com?authuser=1&project=dogsrank) for it.

![Enabling the Indexing API for the dogsrank project. Step 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qi6uzsyisl3ruk2ckpf2.jpg)

![Enabling the Indexing API for the dogsrank project. Step 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/01gl2niv0y2t281gl793.jpg)

> Google does not charge a fee for using this API.

### Creating a service account
1.Go to the page with service accounts and choose our project.

![Creating a service account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jy8vbpgzrcqg4dhb5woz.jpg)

2.Click the **Create Service Account** button. The name of the service account can be arbitrary. Then we will need it for communication with the domain and access rights to it.

![Service Account Details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b98z96dh03w1pmoplbtj.jpg)

3.It is not necessary to set the rights settings. Just click **Done**.
4.Copy the Email of the service account to add it to Search Console.

![List of created service accounts for the selected project
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbsr4zj1ri99di56e9cc.jpg)

5.Go to the **KEYS** tab of the previously created service account and create a JSON key to access the API. A key pair (public and private) will be created, which will then be downloaded to your computer.

![Creating a private key for API access](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/svojo0kjc4jeacpcvqps.jpg)

6.Save the downloaded `.json` for later use.

![List of created keys for the selected project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b2gjq4mvkjjzhv3bylqz.jpg)

### Adding a service account to the owners of the site
1. Go to the [Search Console settings](https://search.google.com/u/0/search-console/settings) page and add the previously created service account to the site owners. Click **Add User**.

![Service account email](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bc2c0vuoc5hiiy9wyika.jpg)

> This article assumes that the domain has already been validated through Search Console.

![Seach Console adding a user](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kgvf1qrv43eik0qjr5rl.jpg)

### Getting an access token and sending links to update indexing

We have successfully created a project, a service account and generated access tokens. Now it's time to try everything in action. 

For example, we will use the PHP language and [API library](https://github.com/dnsinyukov/google-indexing-api).

![GitHub package for working with Google Indexing API](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p8y5tkj0p4hp6u3f4bkt.jpg)

1. Load to the **configs** folder the config that we created at the stage of creating a key for the service account.
2. Create a file `.env` and write the name of the variable `GOOGLE_AUTH_CONFIG` with the same name in the configs folder.
3. Insert all the links you want to update into `/src/urls.txt `file. Add [https://dogsrank.com/](https://dogsrank.com/) to the beginning of file.
4. Open `/src/index.php`.  On `line 18` we see that we call the `updateUrl` method, which will tell Google to index the link.
5. Run the script `php index.php`

**Example API response**
```json
 % php index.php 
Indexing URL: https://dogsrank.com/
200
{
  "urlNotificationMetadata": {
    "url": "https://dogsrank.com/",
    "latestUpdate": {
      "url": "https://dogsrank.com/",
      "type": "URL_UPDATED",
      "notifyTime": "2022-12-04T21:55:33.449222083Z"
    }
  }
}
```

## Related posts
- [Indexing API | Google Developers](https://developers.google.com/search/apis/indexing-api/v3/quickstart)