Excellent software and practical tutorials
introduce
Open Graph ProtocolMake any web page a rich object in the social graph. This is used on Facebook, for example, to allow any web page to have the same functionality as any other object on Facebook.
While many different technologies and patterns exist and can be combined, no single technology provides enough information to richly represent any web page in the social graph. The Open Graph Protocol builds on these existing technologies to give developers one thing to achieve. Simplicity for developers is a key goal of the Open Graph Protocol, and it provides manyTechnical design decisionsProvided information.
Basic metadata
To convert a web page into a graphic object, you need to add a basicMetadataWe are based onRDFaThis means that you will place additionalLabel.
The four required properties for each page are:
og:title
- The title of the object should appear in the diagram, for example "The Rock".og:type
-Objecttype, for example, "video.movie". Additional properties might be required, depending on the type you specify.og:image
- An image URL that should represent an object in the diagram.og:url
- The canonical URL of the object, which will be used as the permanent ID in the graph, e.g. "https://www.imdb.com/title/tt0117500/".
As an example, the followingThe Rock on IMDBOpen Graph protocol tags:
<html prefix="og: https://ogp.me/ns#"> <head> <title>The Rock (1996)</title> <meta property="og:title" content="The Rock" /> <meta property="og:type" content="video.movie" /> <meta property="og:url" content="https://www.imdb.com/title/tt0117500/" /> <meta property="og:image" content="https://ia.media-imdb.com/images/rock.jpg" /> ... </head> ... </html>
Optional metadata
The following properties are optional for any object, and are generally recommended:
og:audio
- The URL of the audio file that accompanies this object.og:description
- A one to two sentence description of your object.og:determiner
- The word that comes before the object's title in the sentence. (a, an, the, "", auto)enumerate.ifauto
Selection, the consumer of the data should choose between "a" or "an". The default value is "" (blank).og:locale
- These tags mark the locale. The format islanguage_TERRITORY
The default isen_US
.og:locale:alternate
-This page can be used forA range of other locales.og:site_name
- If your object is part of a larger website, the display name should be for the entire site. For example, "IMDb".og:video
- The URL of the video file that supplements this object.
For example (line breaks are for display purposes only):
<meta property="og:audio" content="https://example.com/bond/theme.mp3" /> <meta property="og:description" content="Sean Connery found fame and fortune as the suave, sophisticated British agent, James Bond." /> <meta property="og:determiner" content="the" /> <meta property="og:locale" content="en_GB" /> <meta property="og:locale:alternate" content="fr_FR" /> <meta property="og:locale:alternate" content="es_ES" /> <meta property="og:site_name" content="IMDb" /> <meta property="og:video" content="https://example.com/bond/trailer.swf" />
RDF Schema (inTurtlein) can beogp.me/nsFound in.
Structural properties
Some properties can have additional metadata attached to them. This metadata is specified in the same way as usingproperty
Same other metadata ascontent
,butproperty
There will be additional:
.
Shouldog:image
There are some optional attributesStructuringproperty:
og:image:url
- sameog:image
.og:image:secure_url
- If the webpage requires HTTPS, use an alternative URL.og:image:type
- The imageMIME type.og:image:width
- The width in pixels.og:image:height
- High pixel count.og:image:alt
- A description of the image content (not a title). If the page specifies og:image it should specifyog:image:alt
.
Full image example:
Shouldog:video
Tags have the same tags asog:image
Here is an example:
Shouldog:audio
The tag only has the first 3 attributes available (since size doesn't make sense for sounds):
Arrays
If a label can have multiple values, just put multiple versions of the same label on the page. The first label to be used (from top to bottom) takes precedence during conflicts.
A structural attribute is placed after the root tag in which it is declared. Whenever another root element is parsed, the structural attribute is considered completed and another root element begins.
For example:
Indicates that the page has 3 pictures, the first picture is300x300
, the middle image has an unspecified size, and the last image has an1000
Height in px.
Object Type
In order to represent your object in a diagram, you need to specify its type. This is done using the followingog:type
Properties completed:
<meta property="og:type" content="website" />
When the community agrees on a type schema, it is added to the global list of types. All other objects in the type system are of the formCURIE
Global types are grouped vertically. Each vertical has its own namespace. The value of the namespaceog:type
Always prefixed with the namespace followed by a period. This is to reduce confusion with user-defined namespace types, which always have a colon in them.
music
- Namespace URI:
https://ogp.me/ns/music#
og:type
Values:
music:duration
-Integer>=1 - length of the song in seconds.music:album
- music.album array - The album this song is from.music:album:disc
-Integer>=1 - On which disc of the album the song is located.music:album:track
-Integer>=1 - Which song is this?music:musician
-Personal data Arrays- The musician who produced the song.
music:song
- music.song - Songs from this album.music:song:disc
-Integer>=1 - same as thismusic:album:disc
But on the contrary.music:song:track
-Integer>=1 - same as thismusic:album:track
But on the contrary.music:musician
-Personal data- The musician who composed the song.music:release_date
-Date and Time- The date the album was released.
music:song
- with music.albumSame asmusic:song:disc
music:song:track
music:creator
-Personal data- The creator of this playlist.
music:creator
-Personal data- The creator of the site.
video
- Namespace URI:
https://ogp.me/ns/video#
og:type
Values:
video:actor
-Personal data Arrays- Actors in the film.video:actor:role
-String- The roles they play.video:director
-Personal data Arrays- Film director.video:writer
-Personal data Arrays- Screenwriter of the film.video:duration
-Integer>=1 - length of the movie in seconds.video:release_date
-Date and Time- The date the film was released.video:tag
-String Arrays- Tags related to the movie.
video:actor
- with videos.moviessamevideo:actor:role
video:director
video:writer
video:duration
video:release_date
video:tag
video:series
- video.tv_show - Which series this episode belongs to.
Multiple TV episodes. Metadata andvideo.moviesame.
Videos that do not belong to any other category. Metadata andvideo.moviesame.
No vertical
These are globally defined objects that just don't fit in a vertical orientation, but are widely used and agreed upon.
og:type
Values:
article
- Namespace URI:https://ogp.me/ns/article#
article:published_time
-Date and Time- When the article was first published.article:modified_time
-Date and Time- When the article was last modified.article:expiration_time
-Date and Time- When the article expires.article:author
-Personal data Arrays- The author of the article.article:section
-String- High level section name. For example, Technologyarticle:tag
-String Arrays- Tag words related to this article.
book
- Namespace URI:https://ogp.me/ns/book#
book:author
-Personal data Arrays- Who wrote the book.book:isbn
-String- ISBNbook:release_date
-Date and Time- The date the book was published.book:tag
-String Arrays- Tag words related to this book.
profile
- Namespace URI:https://ogp.me/ns/profile#
profile:first_name
-String- A name usually given to an individual by his or her parents or chosen by the individual.profile:last_name
-String- A name inherited from family or marriage, by which the individual is well known.profile:username
-String- A short unique string used to identify them.profile:gender
-enumerate(Male, Female) - Their gender.
website
- Namespace URI:https://ogp.me/ns/website#
No attribution beyond the basic attributes. Any webpage not marked as such should be consideredog:type
website.
type
The following types are used when defining properties in the Open Graph protocol.
type | describe | Word |
---|---|---|
Boolean | Boolean values represent true or false values | True, False, 1, 0 |
Date | DateTime represents a time value consisting of a date (year, month, day) and an optional time component (hours, minutes) | ISO 8601 |
enumerate | A type consisting of a set of bounded constant string values (enumeration members). | String value as an enumeration member |
float | 64-bit signed floating point number | All text that matches the following format: 1.234 |
Integer | 32-bit signed integers. In many languages, integers larger than 32 bits become floating point numbers, so we restrict the Open Graph protocol to facilitate multi-language use. | All text that matches the following format: 1234 |
String | Unicode character sequence | All Unicode characters without escape characters |
Website | A sequence of Unicode characters that identifies an Internet resource. | All valid URLs using https:// or https:// protocol |
Discussion & Support
You can find more information in the Facebook Groupor Developer Mailing ListThe Open Graph Protocol is discussed in . It is currently used by Facebook (See their documentation)、Google(See their documentation)and mixiUsed. It is published by IMDb, Microsoft, NHL, Posterous, Rotten Tomatoes, TIME, Yelp, and many others.
Implementation
There are many parsers and publishing tools developed by the open source community. If you build something cool, let us know on the Facebook group!
- Facebook Object Debugger - Facebook's official parser and debugger
- Google Rich Snippets Testing Tool- Open Graph Protocol support in specific verticals and search engines.
- PHP validator and tokenizer- OGP 2011 Input Validators and Tokenizers in PHP5 Objects
- PHP Consumer - Small library for accessing Open Graph Protocol data in PHP
- OpenGraphNode in PHP - A simple parser for PHP
- PyOpenGraph - A library written in Python for parsing Open Graph protocol information from websites
- OpenGraph Ruby - Ruby Gem that parses web pages and extracts Open Graph protocol tags
- OpenGraph for Java - Small Java class for representing the Open Graph protocol
- RDF::RDFa::Parser - Perl RDFa parser that understands the Open Graph protocol
- WordPress Plugins- Facebook's official WordPress plugin that adds Open Graph metadata to WordPress powered sites.
- Alternative WordPress OGP plugin- A simple, lightweight WordPress plugin that adds Open Graph metadata to your WordPress powered website.