通过 Youtube 数据获取频道订阅列表 Api

Getting channel subscriptions list by Youtube Data Api

有什么方法可以按最近订阅的顺序排列 Youtube 频道的订阅列表吗?

youtube
       .subscriptions()
       .list("snippet")
       .setOrder("")// relevance, unread, alphabetical
       .setMaxResults((long) 1000) // it is not affecting, the max limit is 50
       .setMine(true)
       .execute();

根据文档,我一次最多只能获取50个项目,而且我只有三个订单类型参数relevance, unread, 字母顺序.

但是我需要到达我最后订阅的频道。如果有人帮助我处理这个问题,我将不胜感激。

提前致谢!

根据 the docs,您可以使用以下参数:

myRecentSubscribers (boolean)

This parameter can only be used in a properly authorized request. Set this parameter's value to true to retrieve a feed of the subscribers of the authenticated user in reverse chronological order (newest first).

Note that this parameter only supports retrieval of the most recent 1000 subscribers to the authenticated user's channel. To retrieve a complete list of subscribers, use the mySubscribers parameter. That parameter, which does not return subscribers in a particular order, does not limit the number of subscribers that can be retrieved.

即:在上面代码的 setter 序列中插入类似 .setMyRecentSubscribers(true) 的内容。 (您也可以删除 setChannelId setter 调用,因为通过要求您获得调用此端点的授权,API 已经知道您的调用所指的通道。 )

另请注意,参数的 maxResults 最大值为 50。要仅接收最近的订阅者,请在上面的 setter 序列中输入 .setMaxResults(1)


如果您想获取所有订阅的列表,那么有以下参数:

mine (boolean)

This parameter can only be used in a properly authorized request. Set this parameter's value to true to retrieve a feed of the authenticated user's subscriptions.

在你的 setter 序列中有 .setMine(true)(没有 .setChannelId)。

您必须重复调用 API 的端点才能获得所有订阅,因为该端点提供 paginated result sets. Upon obtaining all those subscriptions, sort them by snippet.publishedAt.

如果您只想获得最近订阅的频道,而不是排序算法,使用最大算法就足够了(O(n)而不是O(n log n))同样 属性.

有关如何在代码中实现分页的示例,请查看 Google 本身提供的一些 sample code

根据您的问题我了解到,您想借助 Youtube Data API V3.

检查您是否在关注特定的 YouTube 频道

为此,document 中提到您可以使用 forChannelId 参数。

Youtube Data API 也有一个 playground,可以让您查看查询结果。您可以简单地在 forChannelId 字段中放置一个 channelId,如果您没有订阅指定频道,结果将 return 一个空数组,如果您订阅了,结果将 return 该指定频道的数据它。

您可以从您的 Java 应用发出一个简单的请求来获取结果。在此代码示例中,我正在检查授权的 youtube API 用户是否订阅了 Firebase Youtube Channel

SubscriptionListResponse response = request.setForChannelId("UC_x5XG1OV2P6uZZ5FSM9Ttw")
        .setMine(true)
        .execute();

响应将在您发出的请求中包含指定频道的详细信息。我也分享了我上面分享的请求的回复。

{
  "kind": "youtube#SubscriptionListResponse",
  "etag": "zCQ7lTwIBgdyVsQmbymEu-fUgjU",
  "pageInfo": {
    "totalResults": 1,
    "resultsPerPage": 5
  },
  "items": [
    {
      "kind": "youtube#subscription",
      "etag": "A-G_B0BnSqn7XtJi7BgHJEk9L3Q",
      "id": "uTEDDg6jpPBwnsim9moHkataEljshwFopudOgIy34nk",
      "snippet": {
        "publishedAt": "2020-07-08T14:02:43.789000Z",
        "title": "Google Developers",
        "description": "The Google Developers channel features talks from events, educational series, best practices, tips, and the latest updates across our products and platforms.",
        "resourceId": {
          "kind": "youtube#channel",
          "channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw"
        },
        "channelId": "UCC77fYySvfP7p-6QGaa-3lw",
        "thumbnails": {
          "default": {
            "url": "https://yt3.ggpht.com/-Fgp8KFpgQqE/AAAAAAAAAAI/AAAAAAAAAAA/Wyh1vV5Up0I/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
          },
          "medium": {
            "url": "https://yt3.ggpht.com/-Fgp8KFpgQqE/AAAAAAAAAAI/AAAAAAAAAAA/Wyh1vV5Up0I/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
          },
          "high": {
            "url": "https://yt3.ggpht.com/-Fgp8KFpgQqE/AAAAAAAAAAI/AAAAAAAAAAA/Wyh1vV5Up0I/s800-c-k-no-mo-rj-c0xffffff/photo.jpg"
          }
        }
      }
    }
  ]
}