Using PHP, how can I get video information like title, description, thumbnail from a youtube video URL e.g.
http://www.youtube.com/watch?v=B4CRkpBGQzU
Using PHP, how can I get video information like title, description, thumbnail from a youtube video URL e.g.
http://www.youtube.com/watch?v=B4CRkpBGQzU
function to get video id from video url
and then
You can get data from youtube oembed interface in two formats: XML and JSON
Interface address: http://www.youtube.com/oembed?url=youtubeurl&format=json
Use this PHP function to get data
Don't forget to enable
extension=php_curl.dll
in yourphp.ini
From oembed:
This returns metadata about a video:
http://www.youtube.com/oembed?url={videoUrlHere}&format=json
Using your example, a call to:
http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=B4CRkpBGQzU&format=json
Returns the following, which you can digest and parse with PHP:
Yet another URL API that can be helpful is: https://www.youtube.com/get_video_info?video_id=B4CRkpBGQzU
video_id is "v" argument of youTube. Result is a dictionary in URL-encoded format (key1=value1&key2=value2&...)
This is undocumented API existing for long time, so exploring it is up to developer. I am aware of "status" (ok/fail), "errorcode" (100 and 150 in my practice), "reason" (string description of error). I am getting duration ("length_seconds") this way because oEmbed does not provide this information (strange, but true) and I can hardly motivate every employer to get keys from youTube to use official API
I wrote this class to display a Youtube video on our website:
And this is how you can use the class:
demo page: http://www.heathernova.us/youtube.php
TTFN Cynthia Fridsma