Skip to content

A Python script to automate URL update and deletion notifications to Google using the Indexing and Search Console APIs. It fetches URLs from an XML sitemap or processes batch URLs from a JSON file, handling Google API authentication and indexing requests.

License

Notifications You must be signed in to change notification settings

srdobolo/Google-Indexing-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google Indexing API Automation Script

This Python script fetches URLs from an XML sitemap and automates the process of notifying Google about updates or deletions of these URLs using the Google Indexing API and Search Console API. The script handles authentication, processes URLs from the sitemap, and sends indexing requests to Google.

Features

  • Fetches URLs from an XML sitemap.
  • Authenticates with Google APIs using a service account.
  • Notifies Google of URL updates (URL_UPDATED) or deletions (URL_DELETED).
  • Supports batch processing of URLs from a JSON file.

Requirements

  • Python 3.7 or higher
  • Google Cloud Platform (GCP) service account with the following APIs enabled:
    • Google Indexing API
    • Google Search Console API

Setup

  1. Clone the repository
    Clone this repository to your local machine:
git clone https://github.com/your-repo/google-indexing-automation.git
  1. Install dependencies Install the required Python libraries:
pip install requests google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client
  1. Set up Google Cloud Platform service account
  • Create a service account in the GCP console.
  • Download the JSON key file for the service account.
  • Replace the (SERVICE_ACCOUNT_FILE) variable in the script with the path to your JSON key file.
  1. Enable APIs Ensure the following APIs are enabled in your GCP project:
  1. Set the sitemap URL Update de (SITEMAP_URL) variable with the URL of your sitemap.

Usage

Notify Google of URL Updates or Deletions

  1. Run the script:
python main.py

The script will:

  • Fetch URLs from the sitemap.
  • Notify Google of updates or deletions for each URL.

Batch Processing URLs from a JSON File

  1. Prepare a JSON file with URLs and actions in the following format:
[
    {"url": "https://example.com/page1", "type": "URL_UPDATED"},
    {"url": "https://example.com/page2", "type": "URL_DELETED"}
]

Call the (send_batch_requests) function with the path to your JSON file:

send_batch_requests("urls.json")

Customization

To notify Google of deletions instead of updates, modify the (notify_google) function call:

notify_google(url, "URL_DELETED")

Update (YOUR_ACCESS_TOKEN) in the (send_request) function with a valid access token if not using service account credentials.

Error Handling

  • If the sitemap cannot be fetched, the script will display an error with the HTTP response code.
  • If a URL notification fails, the script will log the response status and error details.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A Python script to automate URL update and deletion notifications to Google using the Indexing and Search Console APIs. It fetches URLs from an XML sitemap or processes batch URLs from a JSON file, handling Google API authentication and indexing requests.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages