A .NET library for extracting link preview metadata (OpenGraph, Twitter Card, oEmbed) from URLs.
.NET CLI
dotnet add package UrlPreviewParserPackage Manager
Install-Package UrlPreviewParserPackageReference
<PackageReference Include="UrlPreviewParser" Version="1.0.2" />using UrlPreviewParser;
using var client = new UrlPreviewClient();
var result = await client.GetPreviewAsync("https://example.com");
// OpenGraph
Console.WriteLine(result.OpenGraph.Title);
Console.WriteLine(result.OpenGraph.Description);
Console.WriteLine(result.OpenGraph.Image);
// Twitter Card
Console.WriteLine(result.TwitterCard.Title);
Console.WriteLine(result.TwitterCard.Image);
// Basic page title
Console.WriteLine(result.Tags.Title);OpenGraphData extends Dictionary<string, string>. Any og:* property is accessible by key
(e.g., result.OpenGraph["og:title"]). Convenience properties cover the most common fields:
| Property | Key |
|---|---|
Title |
og:title |
Description |
og:description |
Image |
og:image |
Url |
og:url |
Type |
og:type |
SiteName |
og:site_name |
TwitterCardData extends Dictionary<string, string>. Any twitter:* property is accessible
by key (e.g., result.TwitterCard["twitter:label1"]). Convenience properties:
| Property | Key | Notes |
|---|---|---|
Card |
twitter:card |
e.g. summary, summary_large_image |
Title |
twitter:title |
|
Description |
twitter:description |
|
Image |
twitter:image |
Falls back to twitter:image:src |
Url |
twitter:url |
|
Site |
twitter:site |
@username of the website |
Creator |
twitter:creator |
@username of the content creator |
Discovered oEmbed endpoint URLs and the raw response body:
| Property | Type | Description |
|---|---|---|
Json |
string? |
URL of the JSON oEmbed endpoint |
Xml |
string? |
URL of the XML oEmbed endpoint |
Formats |
List<string> |
Discovered format names (e.g. "json", "xml") |
Body |
string? |
Raw response body from the oEmbed endpoint |
Error |
string? |
Error message if the endpoint fetch failed |
| Property | Type | Description |
|---|---|---|
Title |
string? |
Content of the HTML <title> element |
Images |
List<string> |
Image URLs found on the page |
result.Head is a List<Dictionary<string, string?>> containing the raw attributes of every
child element of <head>. Useful when you need access to tags not covered by the typed properties.
When using dependency injection, pass your HttpClient directly. The caller is responsible for
its lifetime; UrlPreviewClient will not dispose it.
// ASP.NET Core — register via IHttpClientFactory
builder.Services.AddHttpClient<MyService>();
// Then inject and use
public class MyService(IHttpClientFactory factory)
{
public async Task<UrlPreviewResult> GetPreviewAsync(string url, CancellationToken ct)
{
var httpClient = factory.CreateClient();
using var client = new UrlPreviewClient(httpClient);
return await client.GetPreviewAsync(url, ct);
}
}ParseAsync parses metadata from an HTML string without making any HTTP requests. The oEmbed
endpoint is discovered but not fetched.
using var client = new UrlPreviewClient();
var result = await client.ParseAsync("https://example.com", htmlString);MIT — see LICENSE for details.