Youtube API(PHP)-如何将(现有)视频添加到现有播放列表? [英] Youtube API (PHP) - how to add (existing) video to existing playlist?

查看:149
本文介绍了Youtube API(PHP)-如何将(现有)视频添加到现有播放列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Youtube API上传一些视频,但是我不知道如何将上传的视频添加到特定的播放列表.我已经在整个Google上进行了搜索,但根本找不到任何帮助.

I am using Youtube API to upload some video, but I can't figure out how to add uploaded video to specific playlist. I have searched all over Google and I haven't found any help at all.

我已经阅读了开发人员指南,并找到了它- https://developers.google. com/youtube/2.0/developers_guide_php#Adding_a_Playlist_Video ,但我不知道如何定义要将脚本添加到哪个现有播放列表中的视频.

I have read developers guide and I found this - https://developers.google.com/youtube/2.0/developers_guide_php#Adding_a_Playlist_Video, but I don't know how to define which video to which existing playlist I want the script to add.

这就是我现在用来上传视频的内容:

This is what I use now to upload 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();

推荐答案

您链接到的文档为您提供了一个起点:

The code in the doc you linked to gives you a starting point:

$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.

Instead of 4XpnKHJAok8 in that example, you'd want to pass in the id of the new video, i.e. the $idv value in your script.

该代码假定您已经有一个$ playlistToAddTo对象,但是您可能会有一个播放列表ID.您可以对其进行修改以使其阅读

That code assumes that you have a $playlistToAddTo object already, but you probably will have a playlist ID instead. You can modify it to read

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

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

where $playlistId is the ID of the playlist you want to add the video to.

这篇关于Youtube API(PHP)-如何将(现有)视频添加到现有播放列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆