dongqixuan3112 2011-11-01 17:41
浏览 27
已采纳

YouTube API getPlaylistVideoFeedUrl问题

I would like to add a video to a playlist using GData. So I have no problem creating the playlist, but I can't manage to add a video to it. Here's what I do:

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

And I get the following error:

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

Which is caused by this code:

$feedUrl = $playlist->getPlaylistVideoFeedUrl();

var_dump shows that the $feed_url is NULL. And it shows that $playlist is an object Zend_Gdata_YouTube_PlaylistListEntry, so I can't understand why it writes "property of non-object".

  • 写回答

1条回答 默认 最新

  • dongzhankou2090 2011-12-24 22:00
    关注

    It seems like it is some kind of a bug in the API. So I've made a little workaround. It may seem ugly, but I had no other ideas.

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

    And simply call it like that:

    addVideosToPlaylist($vids_id, $playlist, $yt);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容