如何通过YouTube官方PHP SDK将YouTube视频添加到播放列表

如何通过YouTube官方PHP SDK将YouTube视频添加到播放列表,youtube,google-api,youtube-api,youtube-data-api,google-api-php-client,Youtube,Google Api,Youtube Api,Youtube Data Api,Google Api Php Client,我正在使用此页面中的代码 将视频上传到youtube。但我找不到地方把上传的视频放到已经存在的播放列表中 我发现这个类有insert方法,但我不知道如何使用它 这就是我想到的 $resourceId = new \Google_Service_YouTube_ResourceId(); $resourceId->setVideoId( $status["id"] ); $resourceId-&

我正在使用此页面中的代码 将视频上传到youtube。但我找不到地方把上传的视频放到已经存在的播放列表中

我发现这个类有
insert
方法,但我不知道如何使用它

这就是我想到的

                $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(GuzzleHttp\Psr7\Request)#698 (7) {
  ["method":"GuzzleHttp\Psr7\Request":private]=>
  string(4) "POST"
  ["requestTarget":"GuzzleHttp\Psr7\Request":private]=>
  NULL
  ["uri":"GuzzleHttp\Psr7\Request":private]=>
  object(GuzzleHttp\Psr7\Uri)#749 (7) {
    ["scheme":"GuzzleHttp\Psr7\Uri":private]=>
    string(5) "https"
    ["userInfo":"GuzzleHttp\Psr7\Uri":private]=>
    string(0) ""
    ["host":"GuzzleHttp\Psr7\Uri":private]=>
    string(18) "www.googleapis.com"
    ["port":"GuzzleHttp\Psr7\Uri":private]=>
    NULL
    ["path":"GuzzleHttp\Psr7\Uri":private]=>
    string(25) "/youtube/v3/playlistItems"
    ["query":"GuzzleHttp\Psr7\Uri":private]=>
    string(29) "part=snippet%2CcontentDetails"
    ["fragment":"GuzzleHttp\Psr7\Uri":private]=>
    string(0) ""
  }
  ["headers":"GuzzleHttp\Psr7\Request":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":"GuzzleHttp\Psr7\Request":private]=>
 array(3) {
    ["content-type"]=>
    string(12) "content-type"
    ["host"]=>
    string(4) "Host"
    ["x-php-expected-class"]=>
    string(20) "X-Php-Expected-Class"
  }
  ["protocol":"GuzzleHttp\Psr7\Request":private]=>
  string(3) "1.1"
  ["stream":"GuzzleHttp\Psr7\Request":private]=>
  object(GuzzleHttp\Psr7\Stream)#730 (7) {
    ["stream":"GuzzleHttp\Psr7\Stream":private]=>
    resource(589) of type (stream)
    ["size":"GuzzleHttp\Psr7\Stream":private]=>
    NULL
    ["seekable":"GuzzleHttp\Psr7\Stream":private]=>
    bool(true)
    ["readable":"GuzzleHttp\Psr7\Stream":private]=>
    bool(true)
    ["writable":"GuzzleHttp\Psr7\Stream":private]=>
    bool(true)
    ["uri":"GuzzleHttp\Psr7\Stream":private]=>
    string(10) "php://temp"
    ["customMetadata":"GuzzleHttp\Psr7\Stream":private]=>
    array(0) {
    }
  }
}
注:
我可以通过API上传视频,这样身份验证和连接以及所有基本要求都可以

这里是一个起点

这是解决用户问题的代码

$(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();
    });
});
您也可以查看下面列出的一些相关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();
          });
      });
      
      您也可以查看下面列出的一些相关SO帖子,了解他们如何在播放列表中上传视频


      在发布问题之前,我已经阅读了这些链接,它们与我遇到的问题无关。我甚至都不知道你贴的代码是干什么的@你解决你的问题了吗?如果是,请发布解决方案,因为我面临相同的问题。是的。我通过在设置播放列表之前重新初始化
      $client
      和`$service,发布了解决方案。我在发布问题之前已经阅读了链接,它们与我遇到的问题无关。我甚至都不知道你贴的代码是干什么的@你解决你的问题了吗?如果是,请发布解决方案,因为我面临相同的问题。是的。我通过在设置播放列表之前重新初始化
      $client
      和`$service,发布了解决方案