Php 显示youtube视频链接(如facebook)的标题和说明
YouTube:像facebook一样获取YouTube标题+图像+描述 现在我正在使用Php 显示youtube视频链接(如facebook)的标题和说明,php,facebook,api,youtube,Php,Facebook,Api,Youtube,YouTube:像facebook一样获取YouTube标题+图像+描述 现在我正在使用 <?php // Replace Youtube URLs with embed code function embedYoutube($text) { $search = '% # Match any youtube URL in the wild. (?:https?://)? # Optional scheme. Either http or https
<?php
// Replace Youtube URLs with embed code
function embedYoutube($text)
{
$search = '% # Match any youtube URL in the wild.
(?:https?://)? # Optional scheme. Either http or https
(?:www\.)? # Optional www subdomain
(?: # Group host alternatives
youtu\.be/ # Either youtu.be,
| youtube\.com # or youtube.com
(?: # Group path alternatives
/embed/ # Either /embed/
| /v/ # or /v/
| /watch\?v= # or /watch\?v=
) # End path alternatives.
) # End host alternatives.
([\w\-]{10,12}) # Allow 10-12 for 11 char youtube id.
\b # Anchor end to word boundary.
%x';
$replace = '<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/$1?fs=1"</param>
<param name="allowFullScreen" value="true"></param>
<param name="allowScriptAccess" value="always"></param>
<embed src="http://www.youtube.com/v/$1?fs=1"
type="application/x-shockwave-flash" allowscriptaccess="always" allowFullScreen="true" width="425" height="344">
</embed>
</object>';
return preg_replace($search, $replace, $text);
}
$string = 'Video1'.
'http://www.youtube.com/watch?v=NLqAF9hrVbY'."\n".
'http://www.youtube.com/v/u1zgFlCw8Aw';
echo embedYoutube($string);
?>
用于嵌入youtube视频,但我希望视频源的完整描述+标题+链接随视频一起显示。
有人有答案吗。可能有点让人头疼,但你可以使用Youtube提要api。这是我自己代码的剪贴画:
$youtube = simplexml_load_file('http://gdata.youtube.com/feeds/api/videos/'.$youtubeID.'?v=2');
$title ='<b>Youtube:</b> '. (string) $youtube->title;
$youtube=simplexml\u加载\u文件('http://gdata.youtube.com/feeds/api/videos/“.$youtubeID.”v=2“;
$title='Youtube:'。(字符串)$youtube->title;
我应该这样做。加载速度也相当快。可能有点让人头疼,但你可以使用Youtube提要api。这是我自己代码的剪贴画:
$youtube = simplexml_load_file('http://gdata.youtube.com/feeds/api/videos/'.$youtubeID.'?v=2');
$title ='<b>Youtube:</b> '. (string) $youtube->title;
$youtube=simplexml\u加载\u文件('http://gdata.youtube.com/feeds/api/videos/“.$youtubeID.”v=2“;
$title='Youtube:'。(字符串)$youtube->title;
我应该这样做。加载速度也相当快。例如,使用CURL从youtube API获取有关youtube视频的更多信息
http://gdata.youtube.com/feeds/api/videos/VS6J_XXVst0?v=2&alt=json&format=5
API例如,使用CURL从youtube API获取有关youtube视频的更多信息
http://gdata.youtube.com/feeds/api/videos/VS6J_XXVst0?v=2&alt=json&format=5
API关于描述或摘要和缩略图,请参见此处:
$url=http://img.youtube.com/vi/“.$youtubeID.”/1.jpg“代码>摘要应该在xml文件中,以便您查看。如果答案正确,请接受。感谢您的帮助,但我仍然无法从中获取描述。$description=(string)$youtube->content
但您可能必须将xml加载程序中的?v=2
更改为?v=1
,此处提供了有关描述、摘要和缩略图的信息:$url='1'http://img.youtube.com/vi/“.$youtubeID.”/1.jpg“代码>摘要应该在xml文件中,以便您查看。如果答案正确,请接受。感谢您的帮助,但我仍然无法从中获取描述。$description=(string)$youtube->content
但是您可能必须在xml加载器中将?v=2
更改为?v=1