【问题标题】:YouTube Zend library get VideoId of playlist entryYouTube Zend 库获取播放列表条目的 VideoId
【发布时间】:2012-07-17 06:59:32
【问题描述】:

我正在使用 Zend GData 库从我的应用程序中管理 YouTube 视频。该应用程序使用户能够根据需要选择将上传的视频添加到他们预先存在的 YouTube 播放列表之一。一个问题是,如果视频随后从我们的应用程序中删除,它似乎会在添加它的播放列表中留下一个“孤立”的已删除视频对象。

我一直在想办法让我们的应用程序先将视频从任何播放列表中删除,然后再从 YouTube 中删除,但我很难弄清楚如何确定播放列表中是否包含特定的 YouTube 视频。

我编写了一个函数,它遍历每个播放列表中与登录用户相关的每个条目,并尝试将播放列表中视频的视频 ID 与作为参数传递的视频 ID 进行比较。但是,我似乎无法获得播放列表中任何视频的视频 ID 值。

函数如下:

function remove_video_from_playlists($yt,$hash){

    $playlistListFeed = $yt->getPlaylistListFeed("default");

    foreach ($playlistListFeed as $playlistListEntry) {


        $playlistVideoFeed = $yt->getPlaylistVideoFeed($playlistListEntry->getPlaylistVideoFeedUrl());

        foreach ($playlistVideoFeed as $playlistVideoEntry) {


        //check to see if each video in the playlist matches the video we are trying to delete
            if($playlistVideoEntry->getMediaGroup()->videoId == $hash){

                $playlistVideoEntry->delete();

            }
        }   
    }
}

任何帮助将不胜感激。如何获取播放列表中每个视频条目的底层 videoId?

【问题讨论】:

  • $playlistVideoEntry->getMediaGroup() 的值是多少?设置好了吗?它是否包含现有视频的值?

标签: php zend-framework youtube gdata playlists


【解决方案1】:

我发现了问题。

我需要在 $yt 对象上将 GData 库版本设置为版本 2

用过这个: $yt->setMajorProtocolVersion(2);

这使得所有奇怪的行为都消失了,并且 $playlistVideoEntry->getMediaGroup()->getVideoId() 的使用按预期工作。

【讨论】:

  • 谢谢,我快疯了。为什么API默认不在2上?呃。顺便说一句,这也适用于我:$playlistVideoEntry->getVideoId();
【解决方案2】:

你试过了吗

$playlistVideoEntry->getMediaGroup()->getVideoId();

因为从 API 中查看,似乎有这样一个函数应该返回您需要的内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-30
    • 1970-01-01
    • 2017-09-01
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多