jon24422531
Technical User
I am a PHP newbie so please forgive what may be a simple request. I have used PHP and JSON to retrieve a view count for a single YouTube video, but I want to list the view count for many more (around 65) probably using an array.
This (predictably) does not work, where am I going wrong?
On a completely unrelated note, I am doing this as a single web page for a visually impaired friend who has recorded these videos, is there any way that the resulting text can be read out when the page loads?
Many thanks
Jonathan
Jonathan
This (predictably) does not work, where am I going wrong?
PHP:
<?php
$vidarray = array("IRQ9bdiq4A4", "ew8TxXHmqzY", "CWQOhEw1vZk", "r4aR49ECD4s");
$arrlength = count($vidarray);
function get_youtube_views($video_ID) {
$JSON = file_get_contents("[URL unfurl="true"]https://gdata.youtube.com/feeds/api/videos?q={$video_ID}&alt=json");[/URL]
$JSON_Data = json_decode($JSON);
$descr = $JSON_Data->{'feed'}->{'entry'}[0]->{'media$group'}->{'media$description'}->{'$t'};
$views = $JSON_Data->{'feed'}->{'entry'}[0]->{'yt$statistics'}->{'viewCount'};
$titles = $JSON_Data->{'feed'}->{'entry'}[0]->{'title'}->{'$t'};
echo "Number of views:" .$views. "<br>";
echo "Description:" .$descr. "<br>";
echo "Title:" .$titles. "<br>";
}
for($x=0;$x<$arrlength;$x++) {
get_youtube_views($vidarray);
}
?>
On a completely unrelated note, I am doing this as a single web page for a visually impaired friend who has recorded these videos, is there any way that the resulting text can be read out when the page loads?
Many thanks
Jonathan
Jonathan