使用 Zend 在 YouTube 上创建私人播放列表
我正在拼命尝试在 YouTube 上创建一个私人播放列表。创建公共播放列表没问题,文档非常好。但是,我无法将说明“翻译”为代码。
您可以使用 API 来更新 播放列表的标题、描述和/或 公共/私人状态。要更新一个 播放列表,修改PlaylistListEntry 该播放列表的对象,然后调用 对象的 save 方法。
我的代码:
$httpClient = isset($_SESSION['sessionToken'])? Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']) : null;
$this->youtube = new Zend_Gdata_YouTube($httpClient, "CompanyName-AppName-0.1", null, $this->apikey);
// ...
$yt = $this->youtube;
$newPlaylist = $yt->newPlaylistListEntry();
$newPlaylist->description = $yt->newDescription()->setText('My Description');
$newPlaylist->title = $yt->newTitle()->setText('My Title');
$postLocation = 'http://gdata.youtube.com/feeds/api/users/default/playlists';
try {
$yt->insertEntry($newPlaylist, $postLocation);
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
最后一部分或多或少是文档中的示例代码。它效果很好,但播放列表是公开的。
据我了解, $newPlaylist
是 PlaylistListEntry
的实例,因此应该有一种方法将其设为私有。我检查了对象源代码(及其超过 9000 个父对象)以及 get_class_methods
的输出,但是我发现没有任何方法使其成为私有的。另外,仅仅尝试将私有/公共成员设置为 true/false 没有帮助,并会导致错误消息(说没有这样的成员)。
我对 YouTube API 和 Zend 不太有经验,如果有人能在这里帮助我,我真的很感激。
I'm desperately trying to create a private playlist on youtube. It's no problem to create public playlists, the docs are very good. However I'm unable to "translate" the instructions to code.
You can use the API to update a
playlist's title, description and or
public/private status. To update a
playlist, modify the PlaylistListEntry
object for that playlist and then call
the object's save method.
My code:
$httpClient = isset($_SESSION['sessionToken'])? Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']) : null;
$this->youtube = new Zend_Gdata_YouTube($httpClient, "CompanyName-AppName-0.1", null, $this->apikey);
// ...
$yt = $this->youtube;
$newPlaylist = $yt->newPlaylistListEntry();
$newPlaylist->description = $yt->newDescription()->setText('My Description');
$newPlaylist->title = $yt->newTitle()->setText('My Title');
$postLocation = 'http://gdata.youtube.com/feeds/api/users/default/playlists';
try {
$yt->insertEntry($newPlaylist, $postLocation);
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
The last part is more or less the sample code from the docs. It works great, but the playlist is public.
From what I understand, $newPlaylist
is an instance of PlaylistListEntry
and thus there should be a method to make it private. I've inspected the object source code (and its over 9000 parent objects) plus the output of get_class_methods
, however I found no method which makes it private. Also just trying to set the private/public member to true/false doesn't help and leads to an error message (saying there's no such member).
I'm not very experienced with the YouTube API and Zend, I'd really appreciate if someone could help me out here.
From what I've read making a playlist private can be done by adding a <yt:private />
tag to the request. This sounds pretty simple, is there maybe a way to manually add it to the request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定播放列表,但一个特定的视频可以在上传时被标记为“私人”:
我知道您正在搜索播放列表,但也许它可以帮助您......例如通过分析代码该方法等
I'm not sur about playlist, but one particural video could be marked like a "private" in the moment of upload by:
I know that you are searching about playlist, but maybe it could help you... for example by analizing code of this method, etc.