PHP code example of sergiocarlosmorales / opengraph
1. Go to this page and download the library: Download sergiocarlosmorales/opengraph library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sergiocarlosmorales / opengraph example snippets
bash
curl -s http://getcomposer.org/installer | php
php composer.phar install
php
php
use Fusonic\OpenGraph\Consumer;
$consumer = new Consumer($httpClient, $httpRequestFactory);
$object = $consumer->loadUrl("http://www.youtube.com/watch?v=P422jZg50X4");
// 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; // http://www.youtube.com/watch?v=P422jZg50X4
// Images
$image = $object->images[0];
echo "Image[0] URL: " . $image->url // https://i1.ytimg.com/vi/P422jZg50X4/maxresdefault.jpg
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 // http://www.youtube.com/v/P422jZg50X4?version=3&autohide=1
echo "Video height: " . $video->height // 1080
echo "Video width: " . $video->width // 1920
echo "Video type: " . $video->type // application/x-shockwave-flash