Youtube API(PHP)-如何将(现有的)视频添加到现有的播放列表?

3
我正在使用Youtube API上传视频,但我不知道如何将已上传的视频添加到特定的播放列表中。我在Google上搜索了很久,但没有找到任何帮助信息。
我阅读了开发人员指南,并找到了这个链接- https://developers.google.com/youtube/2.0/developers_guide_php#Adding_a_Playlist_Video,但我不知道如何定义要将哪个视频添加到现有的播放列表中。
这是我现在用来上传视频的代码:
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); 

$developerKey = 'MYDEVKEY';
$applicationId = 'SOMEID';

$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
              $username = 'user',
              $password = 'pass',
              $service = 'youtube',
              $client = null,
              $source = 'something', 
              $loginToken = null,
              $loginCaptcha = null,
              $authenticationURL);  

    $clientId = 'something';

    $yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);

    $videoName = "video/user_12345.mov";

    $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
    $filesource = $yt->newMediaFileSource($videoName);
    $filesource->setContentType('video/quicktime');
    $filesource->setSlug('video/test.mov');
    $myVideoEntry->setMediaSource($filesource);
    $myVideoEntry->setVideoTitle('Video title');
    $myVideoEntry->setVideoDescription('Video description');
    $myVideoEntry->setVideoCategory('Autos');
    $myVideoEntry->SetVideoTags('car');
    $uploadUrl ='https://uploads.gdata.youtube.com/feeds/users/default/uploads';

    $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
    $state = $newEntry->getVideoState();
    $idv = $newEntry->getVideoId();

我没有使用过YT-API的ZEND框架包的经验,但是这个链接展示了你需要进行的请求类型。你可以使用PHP cURL来发起请求。 - user1190992
1个回答

1

你链接的文档中的代码给了你一个起点:

$postUrl = $playlistToAddTo->getPlaylistVideoFeedUrl();
// video entry to be added
$videoEntryToAdd = $yt->getVideoEntry('4XpnKHJAok8');

// create a new Zend_Gdata_PlaylistListEntry, passing in the underling DOMElement of the VideoEntry
$newPlaylistListEntry = $yt->newPlaylistListEntry($videoEntryToAdd->getDOM());

// post
try {
  $yt->insertEntry($newPlaylistListEntry, $postUrl);
} catch (Zend_App_Exception $e) {
  echo $e->getMessage();
}

在这个例子中,你需要传递新视频的id,即你脚本中的$idv值,而不是4XpnKHJAok8

该代码假定你已经有了一个$playlistToAddTo对象,但实际上你可能只有一个播放列表ID。你可以进行修改:

$postUrl = sprintf('https://gdata.youtube.com/feeds/api/playlists/%s?v=2', $playlistId);

其中$playlistId是您想要将视频添加到的播放列表的ID。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接