OpenGraph-Net 3.2.0

A simple .net assembly to use to parse Open Graph information from either a URL or an HTML snippet.   You can read more about the Open Graph protocol @ http://ogp.me/.

There is a newer version of this package available.
See the version list below for details.
Install-Package OpenGraph-Net -Version 3.2.0
dotnet add package OpenGraph-Net --version 3.2.0
<PackageReference Include="OpenGraph-Net" Version="3.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OpenGraph-Net --version 3.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: OpenGraph-Net, 3.2.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install OpenGraph-Net as a Cake Addin
#addin nuget:?package=OpenGraph-Net&version=3.2.0

// Install OpenGraph-Net as a Cake Tool
#tool nuget:?package=OpenGraph-Net&version=3.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

OpenGraphNet

AppVeyor
Nuget V
Nuget dl
License
gitter

A simple .net assembly to use to parse Open Graph information from either a URL or an HTML snippet. You can read more about the
Open Graph protocol @ http://ogp.me.

Usage

These are the basic operations of the OpenGraphNet parser.

Parsing from a URL

Synchronosly parse a url:

OpenGraph graph = OpenGraph.ParseUrl("https://open.spotify.com/user/er811nzvdw2cy2qgkrlei9sqe/playlist/2lzTTRqhYS6AkHPIvdX9u3?si=KcZxfwiIR7OBPCzj20utaQ");

Use async/await to parse a url:

OpenGraph graph = await OpenGraph.ParseUrlAsync("https://open.spotify.com/user/er811nzvdw2cy2qgkrlei9sqe/playlist/2lzTTRqhYS6AkHPIvdX9u3?si=KcZxfwiIR7OBPCzj20utaQ");

Acessing Values

Accessing Metadata

Each metadata element is is stored as an array. Additionally, each element's properties are also stored as an array.

<meta property="og:image" content="http://example.com/img1.png">
<meta property="og:image:width" content="30">
<meta property="og:image" content="http://example.com/img2.png">
<meta property="og:image:width" content="60">
<meta property="og:locale" content="en">
<meta property="og:locale:alternate" content="en_US">
<meta property="og:locale:alternate" content="en_GB">

You would access the values from the sample HTML above as:

  • graph.Metadata["og:image"].First().Value // "http://example.com/img1.png".
  • graph.Metadata["og:image"].First().Properties["width"].Value() // "30".
  • graph.Metadata["og:image"][1].Value // "http://example.com/img2.png".
  • graph.Metadata["og:image"][1].Properties["width"].Value() // "30".
  • graph.Metadata["og:locale"].Value() // "en"
  • graph.Metadata["og:locale"].First().Properties["alternate"][0].Value // "en_US"
  • graph.Metadata["og:locale"].First().Properties["alternate"][1].Value // "en_GB"

Basic Metadata

The four required Open Graph properties for all pages are available as direct properties on the OpenGraph object.

  • graph.Type is a shortcut for graph.Metadata["og:type"].Value()
  • graph.Title is a shortcut for graph.Metadata["og:title"].Value()
  • graph.Image is a shortcut for graph.Metadata["og:image"].Value()
    Note: since there can be multiple images, this helper returns the URI of the
    first image. If you want to access images or child properties like og:image:width then you
    should instead use the graph.Metadata dictionary.
  • graph.Url is a shortcut for graph.Metadata["og:url"].Value()

Misc

The original url used to generate the OpenGraph data is available from the OriginalUrl property
graph.OriginalUrl.

Creating OpenGraph Data

To create OpenGraph data in memory use the following code:

var graph = OpenGraph.MakeGraph(
    title: "My Title", 
    type: "website", 
    image: "http://example.com/img/img1.png", 
    url: "http://example.com/home", 
    description: "My Description", 
    siteName: "Example.com");
graph.AddMetadata("og", "image", "http://example.com/img/img2.png");
graph.Metadata["og:image"][0].AddProperty("width", "30");
graph.Metadata["og:image"][1].AddProperty("width", "60");
System.Console.Write(graph.ToString());

The previous System.Console.Write(graph.ToString()); will produce the following HTML (formatting added for legibility):

<meta property="og:title" content="My Title">
<meta property="og:type" content="website">
<meta property="og:image" content="http://example.com/img/img1.png">
<meta property="og:image:width" content="30">
<meta property="og:image" content="http://example.com/img/img2.png">
<meta property="og:image:width" content="60">
<meta property="og:url" content="http://example.com/home">
<meta property="og:description" content="My Description">
<meta property="og:site_name" content="Example.com">

OpenGraphNet

AppVeyor
Nuget V
Nuget dl
License
gitter

A simple .net assembly to use to parse Open Graph information from either a URL or an HTML snippet. You can read more about the
Open Graph protocol @ http://ogp.me.

Usage

These are the basic operations of the OpenGraphNet parser.

Parsing from a URL

Synchronosly parse a url:

OpenGraph graph = OpenGraph.ParseUrl("https://open.spotify.com/user/er811nzvdw2cy2qgkrlei9sqe/playlist/2lzTTRqhYS6AkHPIvdX9u3?si=KcZxfwiIR7OBPCzj20utaQ");

Use async/await to parse a url:

OpenGraph graph = await OpenGraph.ParseUrlAsync("https://open.spotify.com/user/er811nzvdw2cy2qgkrlei9sqe/playlist/2lzTTRqhYS6AkHPIvdX9u3?si=KcZxfwiIR7OBPCzj20utaQ");

Acessing Values

Accessing Metadata

Each metadata element is is stored as an array. Additionally, each element's properties are also stored as an array.

<meta property="og:image" content="http://example.com/img1.png">
<meta property="og:image:width" content="30">
<meta property="og:image" content="http://example.com/img2.png">
<meta property="og:image:width" content="60">
<meta property="og:locale" content="en">
<meta property="og:locale:alternate" content="en_US">
<meta property="og:locale:alternate" content="en_GB">

You would access the values from the sample HTML above as:

  • graph.Metadata["og:image"].First().Value // "http://example.com/img1.png".
  • graph.Metadata["og:image"].First().Properties["width"].Value() // "30".
  • graph.Metadata["og:image"][1].Value // "http://example.com/img2.png".
  • graph.Metadata["og:image"][1].Properties["width"].Value() // "30".
  • graph.Metadata["og:locale"].Value() // "en"
  • graph.Metadata["og:locale"].First().Properties["alternate"][0].Value // "en_US"
  • graph.Metadata["og:locale"].First().Properties["alternate"][1].Value // "en_GB"

Basic Metadata

The four required Open Graph properties for all pages are available as direct properties on the OpenGraph object.

  • graph.Type is a shortcut for graph.Metadata["og:type"].Value()
  • graph.Title is a shortcut for graph.Metadata["og:title"].Value()
  • graph.Image is a shortcut for graph.Metadata["og:image"].Value()
    Note: since there can be multiple images, this helper returns the URI of the
    first image. If you want to access images or child properties like og:image:width then you
    should instead use the graph.Metadata dictionary.
  • graph.Url is a shortcut for graph.Metadata["og:url"].Value()

Misc

The original url used to generate the OpenGraph data is available from the OriginalUrl property
graph.OriginalUrl.

Creating OpenGraph Data

To create OpenGraph data in memory use the following code:

var graph = OpenGraph.MakeGraph(
    title: "My Title", 
    type: "website", 
    image: "http://example.com/img/img1.png", 
    url: "http://example.com/home", 
    description: "My Description", 
    siteName: "Example.com");
graph.AddMetadata("og", "image", "http://example.com/img/img2.png");
graph.Metadata["og:image"][0].AddProperty("width", "30");
graph.Metadata["og:image"][1].AddProperty("width", "60");
System.Console.Write(graph.ToString());

The previous System.Console.Write(graph.ToString()); will produce the following HTML (formatting added for legibility):

<meta property="og:title" content="My Title">
<meta property="og:type" content="website">
<meta property="og:image" content="http://example.com/img/img1.png">
<meta property="og:image:width" content="30">
<meta property="og:image" content="http://example.com/img/img2.png">
<meta property="og:image:width" content="60">
<meta property="og:url" content="http://example.com/home">
<meta property="og:description" content="My Description">
<meta property="og:site_name" content="Example.com">

Release Notes

Bug fixes

NuGet packages (2)

Showing the top 2 NuGet packages that depend on OpenGraph-Net:

Package Downloads
RestCms.Api.NETCore
This is the main REST CMS API package. This package contains initialization code, controllers, filters and core middleware required to run the REST CMS client API.
Wechaty
dotnet wechaty

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
3.2.6 6,649 1/28/2021
3.2.5 73 1/28/2021
3.2.4 30,857 3/24/2020
3.2.3 1,056 2/26/2020
3.2.2 224 2/26/2020
3.2.1 1,967 2/7/2020
3.2.0 8,099 6/15/2019
3.1.2 15,368 3/16/2019
3.1.1 475 2/28/2019
3.1.0 1,322 1/18/2019
3.0.0 6,812 12/5/2018
2.2.0 12,111 5/10/2018
2.0.0 786 5/2/2018
1.3.4 15,566 8/17/2016
1.3.3 643 8/16/2016
1.3.2 734 8/15/2016
1.3.1 734 8/15/2016
1.3.0.1 2,153 6/30/2016
1.2.0.1 6,696 4/2/2013
Show less