Вопрос

I have following link http://gdata.youtube.com/feeds/api/videos/tYMYv1zsAxE and it return an xml file in which is located noembed tag in case the video is not embeddable.

i want to create a loop on list of videos to check which is embeddable and which is not.

Это было полезно?

Решение

Based on your clarification, it sounds like you're asking a question about parsing XML. Here's an alternative: get back JSON, and parse that. You can make a request like

http://gdata.youtube.com/feeds/api/videos/tYMYv1zsAxE?v=2&alt=jsonc&prettyprint=true

and then look at the data->accessControl->embed element within the JSON response.

Or, you know, just parse and access the YouTube API XML exactly like you'd parse the XML from any other source. There's nothing magic going on with the YouTube API XML.

Другие советы

$vidID = "tYMYv1zsAxE";
$url="http://gdata.youtube.com/feeds/api/videos/$vidID?v=2&alt=jsonc&prettyprint=true";
$json = file_get_contents($url, true);
$json_output = json_decode($json);
echo $json_output->data->accessControl->embed;

Simple way to check if youtube video is embeddable.

Thanks to @Jeff Posnick

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top