Skip to content

借助 Indexing API,任何网站所有者都可在添加或移除网页时直接告知 Google。这样一来,Google 就能及时整理网页并安排新的抓取,从而带来更优质的用户流量。目前,Indexing API 只能用于抓取包含 JobPosting 或 BroadcastEvent(嵌套于 VideoObject)的网页。

License

Notifications You must be signed in to change notification settings

renfei/GoogleIndexing

Repository files navigation

English | 简体中文

Google Indexing

Latest Stable Version

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.

Installation

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>

Get started

  1. 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.
  2. Send requests to notify Google of new, updated, or deleted web pages.
  3. You may need more quota than the default. To view your current quota and request more quota, see Quota.
  4. Please refer to: https://developers.google.com/search/apis/indexing-api/v3/prereqs

Demo

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

    }
}

About

借助 Indexing API,任何网站所有者都可在添加或移除网页时直接告知 Google。这样一来,Google 就能及时整理网页并安排新的抓取,从而带来更优质的用户流量。目前,Indexing API 只能用于抓取包含 JobPosting 或 BroadcastEvent(嵌套于 VideoObject)的网页。

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages