【问题标题】:Youtube API batch processing to get user's subscriptionsYoutube API 批处理获取用户订阅
【发布时间】:2023-04-06 17:59:02
【问题描述】:

我正在尝试获取用户的订阅列表。您一次只能获得 50 个,所以我想创建一个批处理来一次完成所有操作。

我正在使用 Jquery 和 ajax 发送这样的 POST 请求:

var query = "<feed xmlns='http://www.w3.org/2005/Atom'";
query += "xmlns:media='http://search.yahoo.com/mrss/'";
query += "xmlns:batch='http://schemas.google.com/gdata/batch'"
query += "xmlns:yt='http://gdata.youtube.com/schemas/2007'>";

for(var i = 0; i < loop; ++i)
{
    query += '<entry>';
    query += '<id>http://gdata.youtube.com/feeds/api/users/' + youtube_username + '/subscriptions?max-results=50&start-index=' + ((i * 50) + 1) + '&alt=json</id>';
    query += "<batch:operation type='query'/>";
    query += '</entry>';
}

query += '</feed>';

$.ajax({
    type: 'POST',
    url: 'http://gdata.youtube.com/feeds/api/users/batch?v=2',
    data: query,
    contentType:"application/atom+xml",
    dataType:"xml",
    success: function(data){
        alert(data);
    }
});

当我执行此请求时,我收到错误 400(错误的 url 请求)。然后我尝试使用此 URL 获取条目:

query += '<id>http://gdata.youtube.com/feeds/api/users/' + youtube_username + '/subscriptions/</id>';

但是我收到了这个错误:

元素类型“feed”必须后跟属性规范,“>”或“/>”。

谢谢你,祝你有美好的一天, 凯文

【问题讨论】:

    标签: jquery youtube-api


    【解决方案1】:

    “批处理请求支持对供稿条目的查询 (GET) 操作,但不支持对整个供稿的查询。例如,如果您要发送一个播放列表的批处理请求,您可以包含一个或多个条目来检索有关单个播放列表条目的信息. 但是,批处理请求无法检索包含这些条目的播放列表提要。”,如 https://developers.google.com/youtube/2.0/developers_guide_protocol_batch_processing 中所述

    我更喜欢这样解释:

    另一个例子是视频,如:

    curl -vLk -d "http://www.w3.org/2005/Atom'xmlns:media='http://search.yahoo.com/mrss/'xmlns:batch='http://schemas.google.com/gdata/batch'xmlns:yt='@ 987654327@'>https://gdata.youtube.com/feeds/api/videos/EWKcFuluXpo" -X POST "https://gdata.youtube.com/feeds/api/videos/batch?v=2"

    以及用户/频道的信息示例,如:

    curl -vLk -d "http://www.w3.org/2005/Atom'xmlns:media='http://search.yahoo.com/mrss/'xmlns:batch='http://schemas.google.com/gdata/batch'xmlns:yt='@ 987654332@'>http://gdata.youtube.com/feeds/api/users/GoogleDevelopers" -X POST "http://gdata.youtube.com/feeds/api/users/batch?v=2"

    所以,我认为在不知道条目ID的情况下,通过批处理查询订阅列表是不可能的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-21
      • 1970-01-01
      • 2015-03-27
      • 2019-02-20
      • 2015-03-14
      • 2013-03-16
      • 1970-01-01
      • 2016-03-20
      相关资源
      最近更新 更多