Gnews 1.0.2
dotnet add package Gnews --version 1.0.2
NuGet\Install-Package Gnews -Version 1.0.2
<PackageReference Include="Gnews" Version="1.0.2" />
paket add Gnews --version 1.0.2
#r "nuget: Gnews, 1.0.2"
// 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 =)
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 | Versions 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. |
-
net6.0
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.