doushuichong2589 2012-03-28 06:27
浏览 36
已采纳

PHP:Youtube最新的视频源PHP代码机制

I am currently adapted a code to my website's use but now I would like to change some of its format but it has been a harder task than expected. My code right now is displaying the latest video. But my goal at the moment is to have the code display the videos *thumbnail pic, *video description and *total views. Below is my code, If you think there is a better way to approach this then I am open for suggestions:

<? 
    error_reporting(E_ALL);
    $feedURL = 'http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?max-results=20';
    $sxml = simplexml_load_file($feedURL);
    $i = 0;
    foreach ($sxml->entry as $entry) {
            $media = $entry->children('media', true);
            $url = (string)$media->group->player->attributes()->url;
            $index = strrpos($url, "&");
            $url = substr($url, 0, $index);
            $index = strrpos($url, "watch");
            $url = substr($url, 0, $index) . "v/" . substr($url, $index + 8, strlen($url) - ($index + 8));
            echo '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="250" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="' . $url . '" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="400" height="250" src="' . $url . '" allowscriptaccess="always" allowfullscreen="true"></embed></object>';
            break;
    }

?>

  • 写回答

3条回答 默认 最新

  • douya7309 2012-03-28 06:45
    关注

    Add

    var_dump($entry);exit;
    

    at the first line inside the foreach code, then take a look at the output and search for your thumbnail images. Then you have to follow the path like it was done with the URL ($entry->children(..) and $media->path->to->thumbnail)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料