2011-11-01 1 views
0

GData를 사용하여 재생 목록에 동영상을 추가하고 싶습니다. 따라서 재생 목록을 만드는 데 아무런 문제가 없지만 동영상을 추가 할 수는 없습니다.YouTube API getPlaylistVideoFeedUrl 문제

$playlist = $yt->newPlaylistListEntry(); 
$playlist->summary = $yt->newDescription()->setText("test"); 
$playlist->title = $yt->newTitle()->setText("test2"); 

$postLocation = 'http://gdata.youtube.com/feeds/api/users/default/playlists'; 

$yt->insertEntry($playlist, $postLocation); 

$feedUrl = $playlist->getPlaylistVideoFeedUrl(); 

$videoEntryToAdd = $yt->getVideoEntry(..given id here..); 
$newPlaylistListEntry = $yt->newPlaylistListEntry($videoEntryToAdd->getDOM()); 
$yt->insertEntry($newPlaylistListEntry, $feedUrl); 

그리고 나는 다음과 같은 오류 얻을 : 여기에 내가 무엇을이 코드로 인해 발생

Notice: Trying to get property of non-object in C:...\library\Zend\Gdata\YouTube\PlaylistListEntry.php on line 296

:

$feedUrl = $playlist->getPlaylistVideoFeedUrl(); 

var_dump$feed_urlNULL 것을 보여줍니다 . 그리고 그것은 $playlist이 객체 Zend_Gdata_YouTube_PlaylistListEntry이라는 것을 보여줍니다. 그래서 "non-object의 속성"을 쓰는 이유를 이해할 수 없습니다.

답변

0

API에 버그가있는 것 같습니다. 그래서 약간의 해결 방법을 만들었습니다. 추한 것처럼 보일지 모르지만 나는 다른 아이디어가 없습니다.

function grab_dump($var) 
{ 
    ob_start(); 
    var_dump($var); 
    return ob_get_clean(); 
} 

function getPlayListLink($playlist) { 
    $test = grab_dump($playlist); 
    $test = strstr($test, "http://gdata.youtube.com/feeds/api/playlists/"); 
    return strstr($test, "' countHint='0'", TRUE); 
} 

function addVideosToPlaylist($videos_arr, $playlistEntry, $yt) { 
    $feedUrl = getPlayListLink($playlistEntry); 

    foreach($videos_arr as $video) 
    { 
     $videoEntryToAdd = $yt->getVideoEntry($video); 
     $newPlaylistListEntry = $yt->newPlaylistListEntry($videoEntryToAdd->getDOM()); 
     $yt->insertEntry($newPlaylistListEntry, $feedUrl); 
    } 
} 

그리고 단순히 그런 식으로 호출 :

addVideosToPlaylist($vids_id, $playlist, $yt);