0

有没有办法将频道中所有 youtube 视频的列表放入 PHP 数组中。我需要嵌入 URL、视频标题和描述。

我怎么能这样做?

4

4 回答 4

2

从这里开始:https ://developers.google.com/youtube/v3/

该api应该为您提供所需的东西。

于 2013-05-22T13:27:29.123 回答
1

Youtube API 很容易使用,另一方面,如果你不想处理 HTTP、缓存、url 伪造和格式操作,我推荐 Zend GData 库: http: //framework.zend.com /manual/1.12/en/zend.gdata.youtube.html

$yt = new Zend_Gdata_YouTube();
$videoFeed = $yt->getUserUploads('liz');

比两行代码更容易:)

于 2013-05-22T13:31:25.700 回答
0

我用过

<?php
    $source = 'http://gdata.youtube.com/feeds/api/videos?author=blah';

    // load as string
    $xmlstr = file_get_contents($source);
    $xmlcont = new SimpleXMLElement($xmlstr);
    foreach($xmlcont as $url)
    {
        echo "{$url->id}>{$url->title}>{$url->content}>{$url->published}>\r\n";
    }

?>
于 2013-05-22T14:21:04.653 回答
0

你可以试试这个...

<?php
     if(!(empty($_REQUEST[v])))
      {
      $video=$_REQUEST[v];
      $autoval=1;
      }
      else
      {
      $video="koDeTEM7Uv0";
      $autoval=0;
      }
?>
<div style="float:left; height:182px;">
<object width="268" height="182">
<param name="movie" value="http://www.youtube.com/v/<?php echo $video."&autoplay=".$autoval;?>&fs=0&hl=en_US&ap=%2526fmt%3D18"></param>
<param name="allowFullScreen" value="true"></param>     <param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/<?php echo $video."&autoplay=".$autoval;?>&fs=0&hl=en_US&ap=%2526fmt%3D18" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="268" height="182"></embed>
</object>
</div>
<div style="clear:both; height:7px;"></div>
<?php


    // set feed URL
    $feedURL = 'http://gdata.youtube.com/feeds/api/users/Asterhealthcare/uploads?max-results=3&start-index=1&strict=true';

    // read feed into SimpleXML object
    $sxml = simplexml_load_file($feedURL);
    ?>
     <!-- <h1><?php //echo $sxml->title; ?></h1>-->
    <?php
    // iterate over entries in feed
    $total=count($sxml);

    foreach ($sxml->entry as $entry) {
      // get nodes in media: namespace for media information
      $media = $entry->children('http://search.yahoo.com/mrss/');

       //get video player URL
      $attrs = $media->group->player->attributes();
      $watch = $attrs['url']; 
      $watch=str_replace(array('http://www.youtube.com/watch','&feature=youtube_gdata_player'),'',$watch);

      // get video thumbnail
      $attrs = $media->group->thumbnail[0]->attributes();
      $thumbnail = $attrs['url']; 

      // get <yt:duration> node for video length
      $yt = $media->children('http://gdata.youtube.com/schemas/2007');
      $attrs = $yt->duration->attributes();
      $length = $attrs['seconds']; 

      // get <yt:stats> node for viewer statistics
      $yt = $entry->children('http://gdata.youtube.com/schemas/2007');
      $attrs = $yt->statistics->attributes();
      $viewCount = $attrs['viewCount']; 

      // get <gd:rating> node for video ratings
      $gd = $entry->children('http://schemas.google.com/g/2005'); 
      if ($gd->rating) {
        $attrs = $gd->rating->attributes();
        $rating = $attrs['average']; 
      } else {
        $rating = 0; 
      } 
      ?>

    <a href="<?php echo $watch; ?>"><img src="<?php echo $thumbnail;?>" height="48px" width="82px" border="1" /></a>&nbsp;

    <?php
    }
    ?>
于 2013-05-22T14:00:02.437 回答