Created
May 21, 2012 17:02
-
-
Save phpfunk/2763285 to your computer and use it in GitHub Desktop.
Generating Open Graph Tags for Viddler Videos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
include '/path/to/viddler/api/'; | |
//Create Viddler object | |
$v = new Viddler_V2('YOUR API KEY'); | |
//Authenticate as you | |
$auth = $v->viddler_users_auth(array( | |
'user' => 'YOUR USERNAME', | |
'password' => 'YOUR PASSWORD' | |
)); | |
//Check for the session id, if not found | |
//something went awry | |
if (! isset($auth['auth']['sessionid'])) { | |
//Handle auth error | |
} | |
//Get the video details and the embed code | |
$video = $v->viddler_videos_getDetails(array( | |
'video_id' => 'VIDEO_ID', | |
'add_embed_code' => 1, | |
'sessionid' => $auth['auth']['sessionid'] | |
)); | |
//Check for errors on getting the video details | |
if (isset($video['error'])) { | |
//Handle the video extraction error | |
} | |
//Figure the embed width & height | |
//Will work with any Viddler embed code | |
preg_match_all('/(height|width|h|w)=("|\'*?)([0-9]{2,4})\\2.*?/is', $video['video']['embed_code'], $m); | |
$video_width = ($m[1][0] == 'w' || $m[1][0] == 'width') ? $m[3][0] : $m[3][1]; | |
$video_height = ($m[1][0] == 'w' || $m[1][0] == 'width') ? $m[3][1] : $m[3][0]; | |
//Get the thumbnail width & mime type | |
$thumb = getimagesize($video['video']['thumbnail_url']); | |
$thumb_width = (isset($thumb[0]) && ! empty($thumb[0])) ? $thumb[0] : 114; | |
$thumb_mime = (isset($thumb['mime']) && ! empty($thumb['mime'])) ? $thumb['mime'] : 'image/jpeg'; | |
//Site URL | |
//If you don't use the permalink feature, you can change this to match your site URL | |
$permalink = $video['video']['permalink']; | |
/* | |
Both tags below for og:video:secure_url and og:image:secure_url | |
will not work correctly if your account does not have access | |
to HTTPS. Please omit them or call 1-888-444-1119 to upgrade. | |
*/ | |
?> | |
<!--Video --> | |
<meta property="og:video" content="http://www.viddler.com/player/<?=$video['video']['id']?>/" /> | |
<meta property="og:video:secure_url" content="https://www.viddler.com/player/<?=$video['video']['id']?>/" /> | |
<meta property="og:video:width" content="<?=$video_width?>" /> | |
<meta property="og:video:height" content="<?=$video_height?>" /> | |
<meta property="og:video:type" content="application/x-shockwave-flash" /> | |
<!-- Thumbnail --> | |
<meta property="og:image" content="http://www.viddler.com/thumbnail/<?=$video['video']['id']?>/"/> | |
<meta property="og:image:secure_url" content="https://www.viddler.com/thumbnail/<?=$video['video']['id']?>/" /> | |
<meta property="og:image:type" content="<?=$thumb_mime?>" /> | |
<meta property="og:image:width" content="<?=$thumb_width?>" /> | |
<!-- Details --> | |
<meta property="og:url" content="<?=$permalink?>" /> | |
<meta property="og:title" content="<?=$video['video']['title']?>"/> | |
<meta property="og:type" content="video" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment