【问题标题】:Setting part to snippet and contentDetails using the youtube api使用 youtube api 将部分设置为片段和 contentDetails
【发布时间】:2021-12-24 02:52:19
【问题描述】:

我用 api 做了一些 digging and found 类似的问题。我目前使用 youtube-api 搜索歌曲。我目前将part 设置为snippet,这样我就可以获取缩略图和标题。但是,将部分设置为 sn-p 我无法获得视频的长度或发布视频图像的频道。目前我正在尝试获取视频长度,我需要将part 设置为contentDetails。我尝试了类似的方法,但没有成功,同时使用它们的正确方法是什么?

$(function(){
$("#formen").on("submit",function(e){
    e.preventDefault(); 
    $("#result").html('');
        var request = gapi.client.youtube.search.list({
            order: "viewCount",
            part: "snippet, contentDetails",
            type: "video",   
            q: encodeURIComponent($("#search").val()).replace(/%20/g, "+"), 
            maxResults: 15
        });

    request.execute(function(response) { 
    console.log(response);
        var results = response.result; 
        $.each(results.items, function(index, item) { 
            $.get("item.php", function(data) {  
                $("#result").append(tplawesome(data, [{"title":item.snippet.title, "yturl":item.snippet.thumbnails.high.url, "videoid":item.id.videoId, "channelTitle":item.snippet.channelTitle}])); 
            });
    });
});
});
});

【问题讨论】:

    标签: jquery youtube-api


    【解决方案1】:

    search endpoint 只提供sn-p。

    如果您需要更多视频详细信息,请从搜索结果中获取视频 ID,然后致电 video endpoint。在那里你可以请求你需要的部分,比如 contentDetails。

    【讨论】:

    猜你喜欢
    • 2014-03-06
    • 2016-06-08
    • 2016-07-11
    • 2015-02-08
    • 2013-08-10
    • 2015-12-07
    • 2016-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多