我有一個像這樣的URL,它包含在一個php文件中以查找關於視頻的統計信息。替換爲gdata
因爲gdata不再有效,我應該如何做到這些?我無法在API中找到它! ('http://gdata.youtube.com/schemas/2007'); //獲取節點的觀衆統計 http://gdata.youtube.com/feeds/api/videos/?q= 我不是很確定該怎麼做
-old代碼 - 這就是我的問題所在。我需要弄清楚這是如何用新的API編寫的,
$ media = $ entry-> children('http://search.yahoo.com/mrss/'); //得到媒體的節點:隨着新的API格式ONE本部命名爲媒體信息
$attrs = $media->group->player->attributes(); // get video player URL
$watch = $attrs['url'];
$attrs = $media->group->thumbnail[0]->attributes(); // get video thumbnail
$thumbnail = $attrs['url'];
$yt = $media->children('http://gdata.youtube.com/schemas/2007'); // get <yt:duration> node for video length
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];
$yt = $entry->children('http://gdata.youtube.com/schemas/2007'); // get <yt:stats> node for viewer statistics
$attrs = $yt->statistics->attributes();
$viewCount = $attrs['viewCount'];
$gd = $entry->children('http://schemas.google.com/g/2005'); // get <gd:rating> node for video ratings
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$rating = $attrs['average'];
}else{$rating = 0;}
$vid = preg_replace ('/&feature=youtube_gdata_player/','',$watch); // get video id
$vid = substr($vid, -11);
-old CODE
<?php
error_reporting(0);
if ($_COOKIE['autoexp'] == 'on'){$autoexp = "showresult";}else{$autoexp = "hideresult";}
$query = $_POST['terms'];
$searchnum = $_COOKIE['snum'];
$searchurl = "https://www.googleapis.com/youtube/v3/search?q=".$query."&part=snippet&key=MYAPIKEYISHERE&max-results=50&format=5";
$feedURL = $searchurl; // set feed URL
$sxml = simplexml_load_file($feedURL); // read feed into SimpleXML object
$i = 0;
$i++;
$sn = 1;
if (empty($query)){
print '<tr><td><div style="margin:auto;padding-top:155px;width:300px;height:120px;text-align:center;"><img src="images/logo.png" height="100"></div></td></tr>';
}
foreach ($sxml->entry as $entry) { // iterate over entries in feed
if ($sn <= $searchnum){
$media = $entry->children('http://search.yahoo.com/mrss/'); // get nodes in media: namespace for media information
$attrs = $media->group->player->attributes(); // get video player URL
$watch = $attrs['url'];
$attrs = $media->group->thumbnail[0]->attributes(); // get video thumbnail
$thumbnail = $attrs['url'];
$yt = $media->children('http://gdata.youtube.com/schemas/2007'); // get <yt:duration> node for video length
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];
$yt = $entry->children('http://gdata.youtube.com/schemas/2007'); // get <yt:stats> node for viewer statistics
$attrs = $yt->statistics->attributes();
$viewCount = $attrs['viewCount'];
$gd = $entry->children('http://schemas.google.com/g/2005'); // get <gd:rating> node for video ratings
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$rating = $attrs['average'];
}else{$rating = 0;}
$vid = preg_replace ('/&feature=youtube_gdata_player/','',$watch); // get video id
$vid = substr($vid, -11);
if ($length <= 600){
$i++;
print " <tr class=\"d".($i & 1)."\"><td>";
?>
<table class="searchresults">
<tr><td>
<b>- <a href="#!" onclick="showinfo('<?=$vid?>')"><?php echo $media->group->title; ?></a></b>
</td><td WIDTH="110">
<div style="padding-left:7px;"><B>Length : </B> <?=substr(gmdate("i:s", '00'.$length),1)?></div>
</td><td width="130" align="center">
<a href="#!" onclick="getit('<?=$vid?>');"><IMG SRC="images/mp3.png" onmouseover="this.src='images/mp32.png';" onmouseout="this.src='images/mp3.png';" title="Get MP3"></a>
</td></tr>
</table>
<div id="infodiv-<?=$vid?>" class="<?=$autoexp?>">
<table class="searchresults" style="height:25px;" >
<tr><td>
<div class="menubar2" style="position:relative;top:-5px;">
<div style="float:left;padding-left:10px;position:absolute;margin-top:-1px;z-index:5;"><img src="<?=$thumbnail?>" height="42" border="1"></div>
<div style="float:left;text-align:left;padding-left:85px;color:#333333;"><b>Author:</b> <?php echo $entry->author->name; ?><div style="color:#000000;padding-top:4px;padding-bottom:0px"><small><?=$viewCount?> Views</small></div></div>
<div style="float:right;margin-right:20px;margin-top:9px;border-style:solid;border-width:1px;"><object width= "217" height="30"><param name="movie" value="http://www.youtube.com/v/<?=$vid?>&rel=0&fs=0&theme=light&showinfo=0&modestbranding=1&autohide=0&color=red"></param><param name="allowFullScreen" value="false"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/<?=$vid?>&rel=0&fs=0&theme=light&showinfo=0&modestbranding=1&autohide=0&color=red" type="application/x-shockwave-flash" allowfullscreen="false" width="217" height="30" allowscriptaccess="always"></embed></object></div>
</div>
</td></tr>
</table>
</div>
</td></tr>
<?php
$sn++;
}else{}
}else{}
}
?>
</table>
我怎麼會去再次使這項工作?
獲取信息現在,說這是我想要的搜索視頻的情況下,說:「馬跑」我該怎麼做? –
現在我被我的舊代碼卡住了,我不知道如何轉換它(上面會發布) –