【问题标题】:YouTube API getPlaylistVideoFeedUrl issueYouTube API getPlaylistVideoFeedUrl 问题
【发布时间】:2011-12-19 16:57:21
【问题描述】:

我想使用 GData 将视频添加到播放列表。所以我创建播放列表没有问题,但我无法向其中添加视频。 这是我的工作:

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

我收到以下错误:

注意:试图在 C:...\library\Zend\Gdata\YouTube\PlaylistListEntry.php 第 296 行获取非对象的属性

这是由这段代码引起的:

$feedUrl = $playlist->getPlaylistVideoFeedUrl();

var_dump 表明$feed_urlNULL。而且它显示$playlist是一个对象Zend_Gdata_YouTube_PlaylistListEntry,所以我不明白为什么它写“非对象的属性”。

【问题讨论】:

    标签: php youtube youtube-api gdata


    【解决方案1】:

    这似乎是 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);
    

    【讨论】:

      猜你喜欢
      • 2011-06-24
      • 2016-11-09
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      • 2011-04-06
      • 1970-01-01
      相关资源
      最近更新 更多