我正在使用此页面中的代码https://developers.google.com/youtube/v3/code_samples/php#upload_a_video将视频上传到YouTube。但是我找不到将上传的视频放在已经存在的播放列表中。
我找到了具有insert
方法的Google_Service_YouTube_Resource_PlaylistItems
,但我不知道如何使用
这就是我想出的
$resourceId = new Google_Service_YouTube_ResourceId();
$resourceId->setVideoId( $status["id"] );
$resourceId->setKind('youtube#video');
$playlistItemSnippet = new Google_Service_YouTube_PlaylistItemSnippet();
$playlistItemSnippet->setTitle('First video in the test playlist');
$playlistItemSnippet->setPlaylistId($playlistId);
$playlistItemSnippet->setResourceId($resourceId);
$playlistItem = new Google_Service_YouTube_PlaylistItem();
$playlistItem->setSnippet($playlistItemSnippet);
$playlistItemResponse = $youtube->playlistItems->insert(
'snippet,contentDetails', $playlistItem, array());
这是响应
object(GuzzleHttpPsr7Request)#698 (7) {
["method":"GuzzleHttpPsr7Request":private]=>
string(4) "POST"
["requestTarget":"GuzzleHttpPsr7Request":private]=>
NULL
["uri":"GuzzleHttpPsr7Request":private]=>
object(GuzzleHttpPsr7Uri)#749 (7) {
["scheme":"GuzzleHttpPsr7Uri":private]=>
string(5) "https"
["userInfo":"GuzzleHttpPsr7Uri":private]=>
string(0) ""
["host":"GuzzleHttpPsr7Uri":private]=>
string(18) "www.googleapis.com"
["port":"GuzzleHttpPsr7Uri":private]=>
NULL
["path":"GuzzleHttpPsr7Uri":private]=>
string(25) "/youtube/v3/playlistItems"
["query":"GuzzleHttpPsr7Uri":private]=>
string(29) "part=snippet%2CcontentDetails"
["fragment":"GuzzleHttpPsr7Uri":private]=>
string(0) ""
}
["headers":"GuzzleHttpPsr7Request":private]=>
array(3) {
["Host"]=>
array(1) {
[0]=>
string(18) "www.googleapis.com"
}
["content-type"]=>
array(1) {
[0]=>
string(16) "application/json"
}
["X-Php-Expected-Class"]=>
array(1) {
[0]=>
string(35) "Google_Service_YouTube_PlaylistItem"
}
}
["headerNames":"GuzzleHttpPsr7Request":private]=>
array(3) {
["content-type"]=>
string(12) "content-type"
["host"]=>
string(4) "Host"
["x-php-expected-class"]=>
string(20) "X-Php-Expected-Class"
}
["protocol":"GuzzleHttpPsr7Request":private]=>
string(3) "1.1"
["stream":"GuzzleHttpPsr7Request":private]=>
object(GuzzleHttpPsr7Stream)#730 (7) {
["stream":"GuzzleHttpPsr7Stream":private]=>
resource(589) of type (stream)
["size":"GuzzleHttpPsr7Stream":private]=>
NULL
["seekable":"GuzzleHttpPsr7Stream":private]=>
bool(true)
["readable":"GuzzleHttpPsr7Stream":private]=>
bool(true)
["writable":"GuzzleHttpPsr7Stream":private]=>
bool(true)
["uri":"GuzzleHttpPsr7Stream":private]=>
string(10) "php://temp"
["customMetadata":"GuzzleHttpPsr7Stream":private]=>
array(0) {
}
}
}
注意:我可以通过API上传视频,因此身份验证和连接以及所有基本要求都可以
这是SO帖子的起点。
这是解决用户问题的代码。
$(function() {
$('input.Chilltrap').on('click', function(e) {
var chilltrap = this.id;
if( $("input[name=" + chilltrap + "]").prop('checked') ) {
checkboxstatusCt = "Yes";
}
else {
checkboxstatusCt = "No";
}
var url = "url.php";
var params = "c="+checkboxstatusCt+"&s="+chilltrap;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
$("#error").html(xmlhttp.responseText);
$("#error"). fadeIn('fast');
setTimeout(function(){
$("#error"). fadeOut('slow');
},2000);
}
};
xmlhttp.open("GET", url+"?"+params,true);
xmlhttp.send();
});
});
您也可以检查一些相关的信息,因此下面列出的帖子以了解他们如何在播放列表中上传视频。
- YouTube API(PHP) - 如何将(现有)视频添加到现有播放列表?
- 将视频上传到YouTube的特定播放列表
- 使用YouTube API V3插入播放列表中的视频
- YouTube PHP API-如何使用PlaylistID 将特定视频添加到特定的播放列表