English | 简体中文
The Indexing API allows any site owner to directly notify Google when pages are added or removed. This allows Google to schedule pages for a fresh crawl, which can lead to higher quality user traffic. Currently, the Indexing API can only be used to crawl pages with either JobPosting or BroadcastEvent embedded in a VideoObject. For websites with many short-lived pages like job postings or livestream videos, the Indexing API keeps content fresh in search results because it allows updates to be pushed individually.If you use Apache Maven to manage Java projects, you only need to add corresponding dependencies to the pom.xml files of the projects.
You only need to declare the following dependencies in the pom.xml
file
<dependency>
<groupId>net.renfei</groupId>
<artifactId>googleindexing</artifactId>
<version>1.0.1</version>
</dependency>
- Complete the prerequisites by enabling the Indexing API, creating a new service account, verifying ownership in Search Console, and getting an access token to authenticate your API call.
- Send requests to notify Google of new, updated, or deleted web pages.
- You may need more quota than the default. To view your current quota and request more quota, see Quota.
- Please refer to: https://developers.google.com/search/apis/indexing-api/v3/prereqs
import com.alibaba.fastjson.JSON;
import com.google.api.services.indexing.v3.model.UrlNotificationMetadata;
import net.renfei.googleindexing.GoogleIndexing;
import net.renfei.googleindexing.entity.UrlNotification;
import net.renfei.googleindexing.entity.UrlNotificationType;
public class Demo {
public static void main(String[] args) {
try {
GoogleIndexing googleIndexing = new GoogleIndexing("/Users/renfei/Google/Ren-Fei-5a8df7c2b912.json");
UrlNotification urlNotification = new UrlNotification();
urlNotification.setUrl("https://www.renfei.net");
urlNotification.setType(UrlNotificationType.URL_UPDATED);
UrlNotificationMetadata urlNotificationMetadata = googleIndexing.publish(urlNotification);
System.out.printf(JSON.toJSONString(urlNotificationMetadata));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}