2012-11-14 7 views
0

Youtube 채널의 특정 재생 목록에서 비디오 정보를 가져 오는 PHP 루프가 있지만 비공개 비디오가 발견되면 중단됩니다. 그것은 치명적인 오류를 제공합니다 :youtube api error

Warning: main() [function.main]: Node no longer exists in F:\xampp\htdocs\youtube\index.php on line 30

Warning: main() [function.main]: Node no longer exists in F:\xampp\htdocs\youtube\index.php on line 30

Fatal error: Call to a member function attributes() on a non-object in F:\xampp\htdocs\youtube\index.php on line 35

코드는 제발 도와주세요

<body> 
<div id="mainPlayer" width="425" height="344"> 
</div> 
</div> 
<div id="mainPlaylist" class="grid_6 omega"> 
<h3 class="title">Legal Feed with Kate Wheeler</h3> 
<ul id="playlists"> 
<?php 
// Loop through each video in each playlist 

    // read feed into SimpleXML object 
    // *Moved into header to load main Video as well 
$playlistFeedURL = 'http://gdata.youtube.com/feeds/api/playlists/6549D4CA7BB99B16?v=2'; 
    $sxml = simplexml_load_file($playlistFeedURL); 

    // iterate over entries in feed 
    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']; 



     // 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:videoId> node for Video ID 
     $yt = $media->children('http://gdata.youtube.com/schemas/2007'); 
     $playlistVideoID = $yt->videoid; 


     // 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; 
     } 


     ?> 
     <div class="item"> 
      <span class="thumbnail left" rel="<?php echo $entry->id; ?>"> 
      <a href="<?php echo $watch; ?>" rel="<?php echo $playlistVideoID; ?>" onclick="_run();"><img src="<?php echo $thumbnail;?>" /></a> 
      </span> 
      <a href="<?php echo $watch; ?>" rel="<?php echo $playlistVideoID; ?>" onclick="_run();"><?php echo $media->group->title; ?></a> 
      <span class="attr">Duration:</span> <?php printf('%0.2f', $length/60); ?> min. 
      <div class="clear"></div> 
     </div>  
    <?php 
    } 
?> 
</ul> 
</body> 

이하입니다. 미리 감사드립니다.

+1

사람들이 당신을 도울 수 있도록 관련 코드 부분을 게시하십시오. 또는 오류 메시지를 작동 및 게시 할 수있는 무언가를 시도하십시오. – Ali

+0

피드가 특정 요소를 포함하지 않는 것이 정상입니다 (예 : 업 로더가 평점/좋아요/싫어요를 사용 중지하면 등급 입력란이 누락됩니다. 속성을 읽기 전에 노드가 있는지 확인하십시오. –

답변

0

아마도 DOM을 사용하여 YouTube에서 HTML을 분리 할 수 ​​있습니까? 그 점에 대해서는 칭찬을하지만, 모든 노드가 항상 존재한다고 가정하기 위해 부끄러운 소리를 낸다.

$nodes = $dom->getElementsByTagName('video'); 
$nodes[0]->attribute(....); #<---but whatever if there's no video elements at all? 


if ($nodes->length > 0) { 
    $nodes[0]->attribute(...); #<--only does this if there was at least one video element 
} 
+0

$ playlistFeedURL = link '; $ sxml = simplexml_load_file ($ playlistFeedURL); // 피드의 항목을 반복합니다. foreach ($ sxml-> $ entry 항목) { // 미디어 노드를 얻으십시오 : 미디어 정보의 네임 스페이스 $ media = $ entry-> children ('http : // search .yahoo.com/mrss/'); // 비디오 플레이어 URL 얻기 $ attrs = $ media-> group-> player-> attributes(); $ watch = $ attrs [ 'url']; \t \t // $ attrs에 = $ 미디어 -> 그룹 -> 미리보기 [0] 비디오 미리보기를 얻을 -> 속성(); $ 썸네일 = $ attrs [ 'url']; –

+0

gah. 주석에 코드 블록을 넣지 마십시오. 그것은 시각적 인 쓰레기입니다. 질문을 편집하고 코드 형식을 적절히 사용하여 코드를 배치하십시오 (코드 텍스트를 강조 표시하고 편집기의'{} '버튼을 누르십시오) –