Skip to content
A simple PHP library to read Open Graph data from the web or publish your own resources.
Branch: master
Clone or download


Build Status Total Downloads

A simple library to read Open Graph data from the web and generate HTML code to publish your own Open Graph objects. A fallback mode enables you to read data from websites that do not implement the Open Graph protocol.

Using this library you can easily retrieve stuff like meta data, video information from YouTube or Vimeo or image information from Flickr without using site-specific APIs since they all implement the Open Graph protocol.

See for information on the Open Graph protocol.



The most flexible installation method is using Composer: Simply create a composer.json file in the root of your project:

    "require": {
        "fusonic/opengraph": "@dev"

Install composer and run install command:

curl -s | php
php composer.phar install

Once installed, include vendor/autoload.php in your script.

require "vendor/autoload.php";


Retrieve Open Graph data from a URL

use Fusonic\OpenGraph\Consumer;

$consumer = new Consumer();
$object = $consumer->loadUrl("");

// Basic information of the object
echo "Title: " . $object->title;                // Getting started with Facebook Open Graph
echo "Site name: " . $object->siteName;         // YouTube
echo "Description: " . $object->description;    // Originally recorded at the Facebook World ...
echo "Canonical URL: " . $object->url;          //

// Images
$image = $object->images[0];
echo "Image[0] URL: " . $image->url             //
echo "Image[0] height: " . $image->height       // null (May return height in pixels on other pages)
echo "Image[0] width: " . $image->width         // null (May return width in pixels on other pages)

// Videos
$video = $object->videos[0];
echo "Video URL: " . $video->url                //
echo "Video height: " . $video->height          // 1080
echo "Video width: " . $video->width            // 1920
echo "Video type: " . $video->type              // application/x-shockwave-flash

There are some more properties but these are the basic and most commonly used ones.

Publish own Open Graph data

use Fusonic\OpenGraph\Elements\Image;
use Fusonic\OpenGraph\Elements\Video;
use Fusonic\OpenGraph\Publisher;
use Fusonic\OpenGraph\Objects\Website;

$publisher = new Publisher();
$object = new Website();

// Basic information of the object
$object->title = "Getting started with Facebook Open Graph";
$object->siteName = "YouTube";
$object->description = "Originally recorded at the Facebook World ..."
$object->url = "";

// Images
$image = new Image("");
$object->images[] = $image;

// Videos
$video = new Video("");
$video->height = 1080;
$video->width = 1920;
$video->type = "application/x-shockwave-flash";
$object->videos[] = $video;

// Generate HTML code
echo $publisher->generateHtml($object);
// <meta property="og:description"
//       content="Originally recorded at the Facebook World ...">
// <meta property="og:image:url"
//       content="">
// <meta property="og:site_name"
//       content="YouTube">
// <meta property="og:type"
//       content="website">
// <meta property="og:url"
//       content="">
// <meta property="og:video:url"
//       content=";autohide=1">
// <meta property="og:video:height"
//       content="1080">
// <meta property="og:video:type"
//       content="application/x-shockwave-flash">
// <meta property="og:video:width"
//       content="1920">

HTML code is formatted just for displaying purposes. You may choose between HTML5/XHTML output using the $publisher->doctype property.

Running tests

You can run the test suite with the following command:

phpunit --bootstrap tests/bootstrap.php .


This library is licensed under the MIT license.

You can’t perform that action at this time.