Google Search Engine
A lightweight C# library for integrating Google's Custom Search JSON API into your applications. This library provides a simple interface to perform web searches programmatically using Google's search capabilities.
Features
- Easy-to-use interface for Google Custom Search
- Async/await support
- Configurable search results limit
- Strong error handling
- Fully documented API
Prerequisites
Before using this library, you'll need:
- An API key from supported service
- .NET 8.0 or later
Installation
Install the package via NuGet:
dotnet add package XiansAi.Agent.GoogleSearch
Usage
Here's a basic example of how to use the library:
using XiansAi.Agent.GoogleSearch;
var apiKey = "your_api_key";
var searchEngine = new SearchEngine(apiKey);
try
{
var results = await searchEngine.SearchAsync("NoIsolation AS Norway", 5);
foreach (var item in results.Items)
{
Console.WriteLine($"Title: {item.Title}");
Console.WriteLine($"URL: {item.Link}");
Console.WriteLine($"Snippet: {item.Snippet}");
Console.WriteLine();
}
}
catch (SearchException ex)
{
Console.WriteLine($"Search failed: {ex.Message}");
throw;
}
Error Handling
The library throws SearchException for any API-related errors. Always wrap your search calls in a try-catch block to handle potential errors gracefully.
License
This project is licensed under 99x commercial license. Contact 99x for more information.
Support
For support, please open an issue in the GitHub repository.