【发布时间】:2012-03-16 02:14:35
【问题描述】:
我正在使用 Zend 框架来访问 YouTube 数据 API。下面的函数循环播放我帐户中特定播放列表中的所有视频并计算观看次数。现在我只有一个视频。
当观看次数达到一定数量(出于测试目的,5 次观看)时,我想将视频设置为私有。
我正在使用此代码示例:https://developers.google.com/youtube/2.0/developers_guide_php#Updating_Video_Information
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, null, $developerKey);
$playlistVideoFeed = $yt->getPlaylistVideoFeed('http://gdata.youtube.com/feeds/api/playlists/XXXXXX');
function playCount($playlistVideoFeed, $yt) {
$count = 1;
$totalViews = 0;
foreach ($playlistVideoFeed as $videoEntry) {
// ensure the video entry is not private
if(!$videoEntry->isVideoPrivate()) {
// add this episode's play count to the total view count
$totalViews = $totalViews + $videoEntry->getVideoViewCount();
// if views are X and I can edit this video, set it to private
if($totalViews >= 5) {
$vidID = $videoEntry->getVideoId();
$videoEntryToEdit = $yt->getFullVideoEntry($vidID);
if($videoEntryToEdit->getEditLink() !== null) {
$putUrl = $videoEntryToEdit->getEditLink()->getHref();
$videoEntryToEdit->setVideoPublic();
$yt->updateEntry($videoEntryToEdit, $putUrl);
}
}
$count++;
}
}
return $totalViews;
}
*编辑**
我的问题的第 1 部分已通过包含 global $yt 得到解决。以上代码不再返回以下错误:Fatal error: Call to a member function updateEntry() on a non-object。
现在,剩下的问题:
这不会将视频设为私有。使用示例的setVideoDescription 进行测试也没有做任何事情......没有错误,没有更改。另外,是的,我的浏览量超过 5 次 :)。
有什么想法吗?
*EDIT v2**
解决了我自己的问题。我更新了上面的代码以反映我的解决方案,以防其他人遇到这个问题。
【问题讨论】:
标签: php zend-framework youtube-api