使用 YouTube Data API v3 从播放列表中删除视频
我正在构建一个应用程序,用户可以使用该应用程序通过拖放创建播放列表.我希望他们能够从播放列表中删除视频.但我对文档感到困惑.
I'm building an application with which users can create playlists through drag and drop. I want them to be able to remove videos from a playlist. But I get confused with the docs.
我正在使用 youtube api php 客户端库.请记住,用户已登录.
I'm using the youtube api php client library. Keep in mind that the user is logged in.
$youtubeService = new Google_YouTubeService($client);
$playlistItems = $youtubeService->playlistItems;
$deleteVid = $playlistItems->delete($videocode);
这是来自客户端库的删除函数:
And this is the delete function from the client library :
/**
* Deletes a playlist item. (playlistItems.delete)
*
* @param string $id The id parameter specifies the YouTube playlist item ID for the playlist item that is being deleted. In a playlistItem resource, the id property specifies the playlist item's ID.
* @param array $optParams Optional parameters.
*/
public function delete($id, $optParams = array()) {
$params = array('id' => $id);
$params = array_merge($params, $optParams);
$data = $this->__call('delete', array($params));
return $data;
}
没有任何地方可以指定从哪个播放列表中删除视频.有谁知道如何做到这一点?其他 playlistItem 函数使用 Google_PlaylistItem 对象作为参数.但这只是视频代码的一个字符串......太奇怪了,我自己无法弄清楚这一点.
There's nowhere, where I can specify which playlist to delete the video from. Does anyone have an idea how to do this? The other playlistItem functions use a Google_PlaylistItem object as a parameter. But this one only a string for the videocode... So weird, can't figure this one out on my own.
任何帮助将不胜感激.
PlaylistItemId 对于播放列表是唯一的.因此,两个不同播放列表中的同一视频具有两个不同的播放列表项 ID.
PlaylistItemId is unique for the playlist. So same video in two different playlist has two diferent playlistitemId.
https://developers.google.com/youtube/v3/docs/playlistItems
您只需要为该函数提供 playlistitemId,而不是 videoId.
All you need to give is playlistitemId to that function, not the videoId.
您可以从 playlistItems->list 函数中找到 playlistitemId,指定播放列表参数.
You can find playlistitemId from playlistItems->list function specifying the playlist parameter.