Rust Google Indexing API
A Rust library for interfacing with the Google Indexing API. Notify Google when pages are added, updated, or deleted on your website for faster indexing in search results.
Features
- URL Notifications: Notify Google about URL updates and deletions
- Metadata Retrieval: Fetch metadata about indexed URLs from Google
- Batch Operations: Process multiple URLs efficiently in a single request (up to 100 URLs)
- Async/Await Support: Built with Tokio for modern async Rust applications
- Type-Safe API: Leverages Rust's type system for safer API interactions
- Error Handling: Comprehensive error types for robust applications
Prerequisites
Before using this library, you need to:
- Enable the Google Indexing API in your Google Cloud Console
- Create a Service Account and download the JSON key file
- Grant permissions to the service account in Google Search Console for your property
For detailed setup instructions, see the Google Indexing API documentation.
Installation
Add this to your Cargo.toml:
[]
= "1.0"
= { = "1", = ["full"] }
= "12" # For authentication
Quick Start
Basic Example with Authentication
use ;
use ServiceAccountAuthenticator;
async
Single URL Operations
use ;
let api = url_notifications;
// Notify about an updated URL
let response = api.publish.await?;
// Notify about a deleted URL
let response = api.publish.await?;
// Get metadata about a URL
let metadata = api.get_metadata.await?;
Batch Operations
Process up to 100 URLs in a single request for better performance:
use ;
let api = url_notifications;
let urls = vec!;
let batch_response = api.batch.await?;
// Process batch results
for result in batch_response
API Reference
GoogleIndexingApi::url_notifications()
Creates a new API client for URL notifications.
Methods
publish(token: &str, url: &str, notification_type: UrlNotificationsType) -> Result<T, GoogleApiError>
Notify Google about a single URL update or deletion.
Parameters:
token: OAuth2 access tokenurl: The URL to notify Google aboutnotification_type: EitherUrlNotificationsType::UPDATEDorUrlNotificationsType::DELETED
get_metadata(token: &str, url: &str) -> Result<T, GoogleApiError>
Retrieve metadata about a URL from Google's index.
Parameters:
token: OAuth2 access tokenurl: The URL to get metadata for
batch(token: &str, urls: Vec<String>, notification_type: UrlNotificationsType) -> Result<Vec<ResponseGoogleIndexingBatch>, GoogleApiError>
Notify Google about multiple URLs in a single batch request.
Parameters:
token: OAuth2 access tokenurls: Vector of URLs (up to 100)notification_type: EitherUrlNotificationsType::UPDATEDorUrlNotificationsType::DELETED
URL Notification Types
Error Handling
The library provides comprehensive error handling through the GoogleApiError enum:
use GoogleApiError;
match api.publish.await
Rate Limits
The Google Indexing API has the following quotas:
- 200 requests per day (default quota)
- Request quota increase through Google Cloud Console if needed
For batch operations, each URL in the batch counts toward your quota.
Examples
See the tests directory for more complete examples including:
- Service account authentication
- Batch processing
- Error handling patterns
Requirements
- Rust 1.70 or later
- Tokio runtime for async operations
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.