【问题标题】:Show title and description of youtube video link like facebook显示 youtube 视频链接的标题和描述,如 facebook
【发布时间】:2011-12-08 07:24:42
【问题描述】:

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
    (?: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 视频,但我希望视频源的完整描述 + 标题 + 链接与它一起显示。 有没有人解答一下。

【问题讨论】:

    标签: php facebook api youtube


    【解决方案1】:

    可能有点麻烦,但您可以使用 Youtube 提要 API。这是从我自己的代码中截取的:

    $youtube = simplexml_load_file('http://gdata.youtube.com/feeds/api/videos/'.$youtubeID.'?v=2');
    $title ='<b>Youtube:</b> '. (string) $youtube->title;
    

    应该这样做。加载速度也很快。

    【讨论】:

    • 描述或摘要和缩略图怎么样
    • 点赞在这里:$url = 'http://img.youtube.com/vi/'.$youtubeID.'/1.jpg'; 摘要应该在 xml 文件中,你看看。如果答案正确,请采纳。
    • 感谢您的帮助,但我仍然无法从中得到描述。
    • $description = (string) $youtube-&gt;content; 但您可能需要在 xml-loader 中将 ?v=2 更改为 ?v=1
    【解决方案2】:

    例如,使用 CURL 从 youtube API 获取有关 youtube 视频的更多信息,这里是示例

    http://gdata.youtube.com/feeds/api/videos/VS6J_XXVst0?v=2&alt=json&format=5
    

    APIhttp://code.google.com/apis/youtube/getting_started.html#data_api

    【讨论】:

      猜你喜欢
      • 2011-07-21
      • 2012-02-08
      • 2016-03-05
      • 2023-03-27
      • 2014-02-09
      • 2019-03-30
      • 2010-12-11
      • 1970-01-01
      • 2016-09-25
      相关资源
      最近更新 更多