YouTube API getPlaylistVideoFeedUrl 问题

发布于 2024-12-12 20:31:50 字数 1068 浏览 3 评论 0原文

我想使用 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);

我收到以下错误:

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

这是由以下代码引起的:

$feedUrl = $playlist->getPlaylistVideoFeedUrl();

var_dump 显示 < code>$feed_url 为 NULL。而且它显示 $playlist 是一个对象 Zend_Gdata_YouTube_PlaylistListEntry,所以我无法理解为什么它写“非对象的属性”。

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".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甚是思念 2024-12-19 20:31:50

看起来这是 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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文