Gnews 1.0.2

dotnet add package Gnews --version 1.0.2                
NuGet\Install-Package Gnews -Version 1.0.2                
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="Gnews" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Gnews --version 1.0.2                
#r "nuget: Gnews, 1.0.2"                
#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 Gnews as a Cake Addin
#addin nuget:?package=Gnews&version=1.0.2

// Install Gnews as a Cake Tool
#tool nuget:?package=Gnews&version=1.0.2                

Gnews

Gnews is a C# wrapper for the GNews API. With Gnews, you can easily integrate the GNews API into your C# application and access news articles and metadata from thousands of news sources worldwide.

If you like this project please give a star =)

NuGet Badge

Installation

To install Gnews, you can use the NuGet package manager in Visual Studio. Simply search for "Gnews" and click "Install".

Alternatively, you can install Gnews using the command line:

Install-Package Gnews

Getting Started

Obtain valid GNews API key from the https://gnews.io/.

Without using dependency injection:

var gnewsClient = new GnewsClient(new GnewsClientOptions()
{
    ApiKey = Environment.GetEnvironmentVariable("MY_GNEWS_API_KEY")
});

Using dependency injection:

In your secrets.json or other settings.json

"GnewsClientOptions": {
  //"ApiKey": "Your api key goes here",
  //"ApiBaseAddress": "If api base has been changed (optional. by default: https://gnews.io/api/v4/)"
},
Program.cs
serviceCollection.AddGnewsClient();

or using Environment Variable

serviceCollection.AddGnewsClient(settings => { settings.ApiKey = Environment.GetEnvironmentVariable("MY_GNEWS_API_KEY"); });

NOTE: do NOT put your API key directly to your source code.

After injecting your service you will be able to get it from service provider

var gnewsClient = serviceProvider.GetRequiredService<GnewsClient>();

or injecting in the constructor of your class

public class NewsService
{
    private readonly GnewsClient _gnewsClient;
    
    public NewsService(GnewsClient gnewsClient)
    {
        _gnewsClient = gnewsClient;
    }
}

Search request

var respone = await gnewsClient.Search(new SearchRequest { Q = "Bitcoin" });

foreach (var article in respone.Articles)
{
    Console.WriteLine(article.Title);
}

more details about search request https://gnews.io/docs/v4#search-endpoint

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2 291 3/7/2023
1.0.1 240 3/7/2023 1.0.1 is deprecated because it is no longer maintained and has critical bugs.
1.0.0 231 3/3/2023