Using Java to Bulk Submit URLs to Google Search Console
Today in this article, we will learn how to perform Java-Bulk Submit URLs to Google Search Console. We will Java example to Bulk Submit URLs to Google Search Engine/Console for Indexing or Crawling purpose.
We already learned how to set up the service account, project, and other configurations so that we can leverage Google’s Indexing API before.
Today in this article, we will cover below aspects,
If you have not performed mandatory prerequisites, please follow the below article for more details,
You may find the need to submit the URLs due to many reasons like article update due to new data or upgrade or article enhancement, etc. In such scenarios, it is always difficult to perform indexing manually.
We shall be using below endpoints required for publishing the URLs,
Step1- Define the scope and endpoint
SCOPES = [ “https://www.googleapis.com/auth/indexing“ ]
ENDPOINT = “https://indexing.googleapis.com/v3/urlNotifications:publish“
In your Java code please define the scopes and endpoint as below,
String scopes = "https://www.googleapis.com/auth/indexing"; String endPoint = "https://indexing.googleapis.com/v3/urlNotifications:publish";
Step2 – Include the service account access token
Please include the service account access token in your code. In the last article, we generated a service account token thecodebuzz-da659b2b8b0d.json which is the private key that you use to authenticate the service account using OAuth2.
For more details :
Step3 – Define the body of the request and invoke API
Below is a sample Java code that can be used to send Bulk URLs to Indexing API
JsonFactory jsonFactory = new JacksonFactory();
// thecodebuzz-da659b2b8b0d.json is the private key that you created for your service account.
InputStream in = IOUtils.toInputStream("thecodebuzz-da659b2b8b0d.json");
GoogleCredential credentials =
GoogleCredential.fromStream(in, this.httpTransport, jsonFactory).createScoped(Collections.singleton(scopes));
GenericUrl genericUrl = new GenericUrl(endPoint);
HttpRequestFactory requestFactory = this.httpTransport.createRequestFactory();
// Define all URLs to be submitted to API
String content = "{"
+ "\"url\": \"http://your url .com\","
+ "\"type\": \"URL_UPDATED\","
+ "}";
HttpRequest request =
requestFactory.buildPostRequest(genericUrl, ByteArrayContent.fromString("application/json", content));
credentials.initialize(request);
HttpResponse response = request.execute();
int statusCode = response.getStatusCode();
- In the above code content is defined to contain the URL to be submitted.
- We have to define request format as “application/json”
- getStatusCode lets you verify the status code after executing the API
Once successfully submitted the URLs for indexing, you can see the status code as 200 for the request.
References :
Please follow the below article for more details on prerequisites,
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.
Terimakasih telah membagikan ide luarbiasa ini, saya sangat kagum sebagai seorang pemula.
Hey Alexa- Glad the article was helpful. Thanks