Skip to content

Instantly share code, notes, and snippets.

@mister-ben
Created December 11, 2013 12:34
Show Gist options
  • Save mister-ben/1841f8a47aef79c02713 to your computer and use it in GitHub Desktop.
Save mister-ben/1841f8a47aef79c02713 to your computer and use it in GitHub Desktop.
Basic example of populating Open Graph Metadata from the Video Cloud Media API This expects the video ID to be in the URL as a query parameter - bctid. Would be good to cache this as the information retrieved would be quite static. Requires PHP Media API wrapper https://github.com/BrightcoveOS/PHP-MAPI-Wrapper
<?php
$bc_player_id = '123456789'; // Player to use on Facebook - usually your viral player
$bc_player_key = 'AQ~~,AAAAABCDEFGabcdefg123456789'; // The player key for the same player
$bc_video_id = '123456789'; // Default video ID - overridden by ?bctid if present
$bc_japan_account = false; // Set to true only if a Brightcove Japan account
$bc_read_token = 'ABCDEFG123456789abcdefg123456789'; // Your read token
// https://github.com/BrightcoveOS/PHP-MAPI-Wrapper
require('bc-mapi.php');
$bc = new BCMAPI($bc_read_token, 'noWriteTokenNeeded');
if ($bc_japan_account == true) {
$bc->__set('url_read', 'api.brightcove.co.jp/services/library?');
$bc->__set('url_write', 'api.brightcove.co.jp/services/post');
$bc_domain = "brightcove.co.jp";
} else {
$bc_domain = "brightcove.com";
}
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if (isset($_GET['bctid'])) {
$bc_video_id = $_GET['bctid'];
}
$params = array('video_id' => $bc_video_id,'video_fields' => 'name,shortDescription,videoStillURL,videoFullLength');
$video = $bc->find('videoById', $params);
?><meta property="og:title" content="<?= htmlspecialchars($video->name); ?>"/>
<meta property="og:description" content="<?= htmlspecialchars($video->shortDescription); ?>"/>
<meta property="og:image" content="<?=$video->videoStillURL; ?>"/>
<!-- Cannonical URL - if this is a different page, Facebook will look for Open Graph there and ignore everything here -->
<meta property="og:url" content="<?=$url; ?>"/>
<meta property="og:type" content="movie"/>
<meta property="og:video" content="http://c.<?= $bc_domain ?>/services/viewer/federated_f9/<?=$bc_player_id; ?>?isVid=1&isUI=1&playerKey=<?=$bc_player_key; ?>&videoId=<?= $bc_video_id; ?>&autoStart=true"/>
<meta property="og:video:secure_url" content="https://secure.<?= $bc_domain ?>/services/viewer/federated_f9/<?=$bc_player_id; ?>?isVid=true&isUI=true&playerKey=<?=$bc_player_key; ?>&secureConnections=true&%40videoPlayer=<?= $bc_video_id; ?>&autoStart=true"/>
<!-- Video size. It's the aspect ratio that's important. Facebook shows the player at different sizes in different places -->
<!-- If using a non-Chromeless player you'd want to add space for the player controls -->
<meta property="og:video:height" content="<?=$video->videoFullLength->frameHeight; ?>"/>
<meta property="og:video:width" content="<?=$video->videoFullLength->frameWidth; ?>"/>
<meta property="og:video:type" content="application/x-shockwave-flash"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment