2011-08-21 1 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 : 파서 ​​오류 : simplexml_load_file() function.simplexml : 문헌 라인 214

경고에 /home/public_html/panel/index.php에 비어 -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 : 파서 ​​오류 :] simplexml_load_file() [function.simplexml로드 파일 : 태그 예상, '<'라인에 /home/public_html/panel/index.php에서 찾을 수 없습니다 (214)

경고를 시작으로 /home/public_html/panel/index.php on line 214

경고 : simplexml_load_file (function.simplexml-load-file) :^in /home/public_html/panel/index.php 온라인 214

+0

'파서 오류 유튜브 데이터 API 버전 3.0 : 문서가 –

답변

2

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

주요

기능은 여기 내 방법입니다.

사용

$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. URL에서 :1을 제거하면 브라우저에있을 때 파일을로드합니다.

+0

패트릭 empty'되어, 지금 막 기존에 코드를 대체 응답에 대한 감사 내가 얻으려고 동일한 동영상에서 제목을 리디렉션하는 제목입니다. –

0

내 방법 :

$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