得到

2011-08-21 15 views
-1

我使用下面的代碼來獲得一些YouTube的視頻,這是以前工作正常的標題YouTube視頻的標題,但我正在從最近幾天一些錯誤/警告,得到

$entry = simplexml_load_file('http://gdata.youtube.com/feeds/api/videos/' . $key); 
return ($entry) ? ucwords(strtolower($entry->children('http://search.yahoo.com/mrss/')->group->title)) : false; 

警告:使用simplexml_load_file()[function.simplexml負荷文件]:http://gdata.youtube.com/feeds/api/videos/jIP4xI9C8us:1:分析器錯誤:文檔是在線路214

警告在/home/public_html/panel/index.php空:使用simplexml_load_file()[function.simplexml -load-file]:在214行/home/public_html/panel/index.php

警告:使用simplexml_load_file()[function.simplexml負荷文件]:^中的線/home/public_html/panel/index.php 214

警告:使用simplexml_load_file()[function.simplexml負荷文件]:http://gdata.youtube.com/feeds/api/videos/jIP4xI9C8us:1:分析器錯誤:開始標記預期, '<' 在/home/public_html/panel/index.php沒有發現在線路214

警告:使用simplexml_load_file()[function.simplexml負荷文件]:在在線214上的/home/public_html/panel/index.php

警告:simplexml_load_file()[function.simplexml-load-file]:^ 214行中的/home/public_html/panel/index.php

+0

'分析器錯誤:文檔被empty' –

回答

2

是我的方式。

使用YouTube數據API v3.0的

$searchResponse = $youtube->videos->listVideos('id','snippet,statistics', 
     array('id' => 'CSV_VIDEO_IDS_HERE', 
       'fields' => 'items(id,snippet(title,publishedAt,channelId,channelTitle,thumbnails(default),description),statistics)' 
    )); 

foreach($searchResponse["items"] as $item) 
{ 
    echo "video titles: ".$item['snippet']['title']; 
} 

google-api-php-client library

0

您可以嘗試用以下函數替換您的電話simplexml_load_file並查看它是否有相同的問題?聽起來像你的主機可能已經改變了一些PHP安全設置。

function load_youtube_xml($url) { 
    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_REFERER, 'http://www.YourWebSiteName.com/'); 
    $response = curl_exec($curl); 
    curl_close($curl); 
    return $response; 
} 
$xml = load_youtube_xml(YOUTUBE_URL); 

P.S.當我從您的URL中刪除:1時,它會在瀏覽器中加載文件。

+0

帕特里克,你的迴應,我剛剛更換的代碼與現存感謝時,我試圖讓將其重定向YouTube標題放在同一個視頻上。 –

0

我的方式:這裏

功能

function getVideoInfo($videoID){ 
    if($videoID == ""){ 
     return false; 
    } 
    /* Get the xml file from YouTube Data API */ 
    $books = simplexml_load_file('http://gdata.youtube.com/feeds/api/videos/'.$videoID); 
    $user = $books->author[0]->name; 
    $desc = $books->content[0]; 
    $title = $books->title[0]; 
    $link = 'http://www.youtube.com/watch?v='.$videoID; 

    return array($user, $title, $desc, $link); 
} 

主要

$info = getVideoInfo($YourVideoID); 
    echo $info[0]; //username 
    echo '<br />'; 
    echo $info[1]; //title 
    echo '<br />'; 
    echo $info[2]; //description 
    echo '<br />'; 
    echo $info[3]; //link