XiansAi.Agent.GoogleSearch
1.0.0
See the version list below for details.
dotnet add package XiansAi.Agent.GoogleSearch --version 1.0.0
NuGet\Install-Package XiansAi.Agent.GoogleSearch -Version 1.0.0
<PackageReference Include="XiansAi.Agent.GoogleSearch" Version="1.0.0" />
paket add XiansAi.Agent.GoogleSearch --version 1.0.0
#r "nuget: XiansAi.Agent.GoogleSearch, 1.0.0"
// Install XiansAi.Agent.GoogleSearch as a Cake Addin #addin nuget:?package=XiansAi.Agent.GoogleSearch&version=1.0.0 // Install XiansAi.Agent.GoogleSearch as a Cake Tool #tool nuget:?package=XiansAi.Agent.GoogleSearch&version=1.0.0
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:
- A Google Cloud Platform account
- A Custom Search Engine ID
- An API key from Google Cloud Console
- .NET 6.0 or later
Installation
Install the package via NuGet:
dotnet add package XiansAi.Agent.GoogleSearch
Configuration
- Create a Custom Search Engine at Google Programmable Search Engine
- Get your Search Engine ID from the created search engine
- Create an API key in the Google Cloud Console
- Enable the Custom Search API
- Create credentials (API key)
Usage
Here's a basic example of how to use the library:
using XiansAi.Agent.GoogleSearch;
// Initialize the search engine
var apiKey = "your_api_key";
var searchEngineId = "your_search_engine_id";
var searchEngine = new SearchEngine(apiKey, searchEngineId);
try
{
// Perform a search with a limit of 5 results
var results = await searchEngine.SearchAsync("NoIsolation AS Norway", 5);
// Process the results
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.
Development
Building from Source
dotnet build --configuration Release
Running Tests
dotnet test
Publishing
To publish a new version to NuGet:
- Update version numbers in both
.csproj
and.nuspec
files - Build in Release mode:
dotnet build --configuration Release
- Create the NuGet package:
dotnet pack --configuration Release
- Push to NuGet.org:
dotnet nuget push bin/Release/XiansAi.Agent.GoogleSearch.[version].nupkg --source https://api.nuget.org/v3/index.json --api-key [your-api-key]
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.
Support
For support, please open an issue in the GitHub repository.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.