2012-11-17 29 views
0

林檢索最近的YouTube評論視頻:的Youtube API的評論限制使用下面的代碼

<?php 
$videoId='lWA2pjMjpBs'; 
$url="http://gdata.youtube.com/feeds/api/videos/{$videoId}/comments"; 
$comments=simplexml_load_file($url); 
foreach($comments->entry as $comment) 
{ 
echo '<fieldset>'.$comment->content.'</fieldset>'; 
} 
?> 

和我有2個問題: 1)有沒有什麼辦法來限制評論數,這樣我就可以顯示只有10個評論的例子? 2)是否可以排除標記爲垃圾郵件的評論?

謝謝。

回答

1

我不知道垃圾郵件,但你可以限制nr。這樣的客戶端解決方案的意見:

$maxcomments = 10; //set max here 
$commentcounter = 0; //add this 

foreach($comments->entry as $comment) 
{ 
    if($commentcounter < $maxcomments) 
    { 
     echo '<fieldset>'.$comment->content.'</fieldset>'; 
    } 

    $commentcounter++; 
} 

沒有檢查過,但它應該工作。我希望這有助於。

+0

經過測試和工作,謝謝。 –

+0

不客氣,如果足夠了,請將它設置爲已接受的答案。 –