这是一个完整而彻底的 hack,我遇到了同样的问题,所以我进入了 Zend/Gdata/YouTube/PlaylistListEntry.php 的第 229 行的课程,我注释掉了 if else 语句。
/**
* Returns the Id relating to the playlist.
*
* @throws Zend_Gdata_App_VersionException
* @return Zend_Gdata_YouTube_Extension_PlaylistId The id of this playlist.
*/
public function getPlaylistId()
{
/*if (($this->getMajorProtocolVersion() == null) ||
($this->getMajorProtocolVersion() == 1)) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The yt:playlistId ' .
'element is not supported in versions earlier than 2.');
} else {*/
return $this->_playlistId;
//}
}
我很想有人向我们展示如何以正确的方式解决这个问题,但这让它变得如此
function printPlaylistListEntry($playlistListEntry, $showPlaylistContents = false)
{
$this->yt->setMajorProtocolVersion(2);
echo '<br>Title: ' . $playlistListEntry->title->text . "\n";
echo '<br>Description: ' . $playlistListEntry->description->text . "\n";
echo '<br>playlistId: ' . $playlistListEntry->playlistId->text . "\n";
...(来自 youtube v2 php api)。
将返回播放列表 ID。
标题:正确的标题
描述:正确的描述
playlistId:正确的playlistId
编辑:我认为这可能是一个更好的解决方案:
if ($this->getMajorProtocolVersion() < 2) {
require_once 'Zend/Gdata/App/VersionException.php';
throw new Zend_Gdata_App_VersionException('The yt:playlistId ' .
'element is not supported in versions earlier than 2.');
} else {
return $this->_playlistId;
}
将 getPlaylistId() 函数替换为 this,遵循前面的 getDescription 函数的逻辑,并且它的 hacky 更少。再次完全接受来自 zend 人的关于为什么这是或不是一个好主意的批评。