A simple way to access the Webhose.io API from your .NET code. Supported .NET frameworks are .NET 3.5 and higher.
using webhoseio;
var client = new WebhoseClient(token: YOUR_API_KEY);
var output = await client.QueryAsync("search", new Dictionary<string, string> { { "q", "github" } });
Console.WriteLine(output["posts"][0]["text"]); // Print the text of the first post
Console.WriteLine(output["posts"][0]["published"]); // Print the text of the first post publication date
// Get the next batch of posts
output = await output.GetNextAsync();
Console.WriteLine(output["posts"][0]["thread"]["site"]); // Print the site of the first post
To make use of the webhose.io API, you need to obtain a token that would be used on every request. To obtain an API key, create an account at https://webhose.io/auth/signup, and then go into https://webhose.io/dashboard to see your token.
You can install using NuGet:
Install-Package webhoseio
To get started, you need to import the library, and set your access token.
(Replace YOUR_API_KEY
with your actual API key).
using webhoseio;
var client = new WebhoseClient(token: YOUR_API_KEY);
API Endpoints
The first parameter the Query
function accepts is the API endpoint string. Available endpoints:
filterWebData
- access to the news/blogs/forums/reviews APIproductSearch
- access to data about eCommerce products/servicesdarkWebAPI
- access to the dark web (coming soon)
Now you can make a request and inspect the results:
var output = await client.QueryAsync("search", new Dictionary<string, string> { { "q", "github" } });
Console.WriteLine(output["totalResults"]);
// 15565094
Console.WriteLine(output["posts"].Count());
// 100
Console.WriteLine(output["posts"][0]["language"]);
// english
Console.WriteLine(output["posts"][0]["title"]);
// Putting quotes around dictionary keys in JS
For your convenience, the ouput object is iterable, so you can loop over it and get all the results of this batch (up to 100).
var totalWords = 0;
foreach(var post in output["posts"])
{
totalWords += post["text"].ToString().Split(' ').Length;
}
Console.WriteLine(totalWords);
// 8822
Creates new client with the provided API key.
Arguments:
token
- your API key
Creates new client with the API key read from appSettings
with key webhoseio:token
.
Example App.config
or Web.config
:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="webhoseio:token" value="YOUR_API_KEY" />
</appSettings>
</configuration>
Construct query and fetch first page of results.
Signature: Task<WebhoseJsonResponseMessage> WebhoseClient.QueryAsync(string endpoint, IDictionary<string, string> parameters)
Arguments:
endpoint
:filterWebData
- access to the news/blogs/forums/reviews APIproductSearch
- access to data about eCommerce products/servicesdarkWebAPI
- access to the dark web (coming soon)
parameters
: A key value dictionary. The most common key is the "q" parameter that hold the filters Boolean query. Read about the available filters.
WebhoseClient client = new WebhoseClient();
WebhoseJsonResponseMessage response = await client.QueryAsync("search", new Dictionary<string, string> { { "q", "github" } }));
Synchronous variant of Json(endpoint, parameters)
.
Signature: WebhoseJsonResponseMessage WebhoseClient.Query(string endpoint, IDictionary<string, string> parameters)
WebhoseClient client = new WebhoseClient();
WebhoseJsonResponseMessage response = client.Query("search", new Dictionary<string, string> { { "q", "github" } }));
Response object as Newtonsoft.Json
object.
Signature: JObject Json { get; }
Fetch the next page of results.
Signature: Task<WebhoseJsonResponseMessage> WebhoseJsonResponseMessage.GetNextAsync()
WebhoseJsonResponseMessage output = await response.GetNextAsync();
Synchronous variant of GetNextAsync()
.
Signature: WebhoseJsonResponseMessage WebhoseJsonResponseMessage.GetNext()
WebhoseJsonResponseMessage output = response.GetNext();