【问题标题】:Adding video to playlist with Youtube API使用 Youtube API 将视频添加到播放列表
【发布时间】:2016-07-31 14:51:10
【问题描述】:

我已成功将视频添加到播放列表,但它被添加了多次(有时两次,有时更多)。有人可以帮忙吗?

$resourceId = new Google_Service_YouTube_ResourceId();
$resourceId->setVideoId($videoID);
$resourceId->setKind('youtube#video');

$playlistItemSnippet = new Google_Service_YouTube_PlaylistItemSnippet();

$playlistItemSnippet->setPlaylistId($playlistId);
$playlistItemSnippet->setResourceId($resourceId);

$playlistItem = new Google_Service_YouTube_PlaylistItem();
$playlistItem->setSnippet($playlistItemSnippet);

$playlistItemResponse = $youtube->playlistItems->insert('snippet,contentDetails', $playlistItem, array());

【问题讨论】:

    标签: php youtube-api


    【解决方案1】:

    自己解决了这个问题,我为此感到非常自豪:)

    我意识到 ajax 在鼠标悬停时触发了上述 php 脚本。因此,每次我将鼠标悬停在复选框元素之外时,php 脚本都会触发多次。

    我用以下代码更改了鼠标悬停代码:

    $(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();
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-31
      • 2014-02-09
      • 1970-01-01
      • 2018-03-10
      • 2014-02-12
      • 2013-01-20
      • 1970-01-01
      • 2023-03-24
      相关资源
      最近更新 更多