XiansAi.Agent.GoogleSearch 1.0.0

There is a newer version of this package available.
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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XiansAi.Agent.GoogleSearch" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XiansAi.Agent.GoogleSearch --version 1.0.0                
#r "nuget: XiansAi.Agent.GoogleSearch, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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:

  1. A Google Cloud Platform account
  2. A Custom Search Engine ID
  3. An API key from Google Cloud Console
  4. .NET 6.0 or later

Installation

Install the package via NuGet:

dotnet add package XiansAi.Agent.GoogleSearch

Configuration

  1. Create a Custom Search Engine at Google Programmable Search Engine
  2. Get your Search Engine ID from the created search engine
  3. 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:

  1. Update version numbers in both .csproj and .nuspec files
  2. Build in Release mode:
    dotnet build --configuration Release
    
  3. Create the NuGet package:
    dotnet pack --configuration Release
    
  4. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last updated
1.0.1 63 1/18/2025
1.0.0 62 1/18/2025