What I am trying to do is fetch the video information for each video from a YouTube channel and just print them out on a page, there are only 15 videos so it should be well within the usage limits.
I have read a few tutorials on websites and many SO questions but I still can't seem to put together what I need :/
The following is my attempt so far:
$url = 'http://gdata.youtube.com/feeds/api/videos?max-results=20&alt=jsonc&orderby=published&format=5&safeSearch=none&author=OpticalExpressUK&v=2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $url);
$body = curl_exec($ch);
curl_close($ch);
$data = json_decode($body, true);
echo '<pre>';
var_dump($data);
echo '</pre>';
// trying to get something out of the array!
echo $data[1]['title'];
The foundations of this came from: php youtube json decode
I've also looked at Looping code using PHP
My ideal output would be something along the lines of:
Video Title
Video Description
Rating
Anything else useful that is returned in the json response.
Embedded video
I know it may only be possible to get the direct link for the video but after reading about this I'm sure I would be able to get it embedded if I could get it that far.
I've also changed the json
in the url to 'jsonc', there seems to be a big difference between what each returns, reason I changed was because I'm sure on YouTube it says to use jsonc?
Any help is much appreciated!