如何通过youtube等排序方式检索最近的订阅者?

时间:2018-12-04 06:40:25

标签: javascript sorting google-api youtube-data-api google-api-js-client

我使用简单的方法,例如我们

buildApiRequest('GET','/youtube/v3/channels',
{
  'mySubscribers': true,
  'maxResults': MaxResult,
  'part': 'snippet'
}

它可以工作,但是结果我看不到如何对其进行排序。 我需要最后一个MaxResult订阅者,我想按频道上的加入日期对它们进行排序。

1 个答案:

答案 0 :(得分:0)

将myRecentSubscribers设置为true的subscriptions.list和SubscriberSnippet返回您的频道中已重新发送的订阅者列表。它不会返回所有这些。

如果您查看回复,则会发现没有日期。您将看不到有人订阅的时间。

"subscriberSnippet": {
    "title": string,
    "description": string,
    "channelId": string,
    "thumbnails": {
      (key): {
        "url": string,0
        "width": unsigned integer,
        "height": unsigned integer
      }
    }

order参数应允许您按标题排序,而不能更改其排序依据。

buildApiRequest('GET',
            '/youtube/v3/subscriptions',
            {'part': 'subscriberSnippet',
             'myRecentSubscribers': 'true',
              'order', 'alphabetical'});

回复

{
 "kind": "youtube#subscriptionListResponse",
 "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/wLsZnuAVb0T9-bdRdCnreaWBHNM\"",
 "nextPageToken": "CAUQAA",
 "pageInfo": {
  "totalResults": 7,
  "resultsPerPage": 5
 },
 "items": [
  {

  "kind": "youtube#subscription",
   "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/3_huGriwUWV4fbbzcclmEoNYJ3w\"",
   "id": "moP_YQe1scKJgrI0udrz3B2tJTmRwvz4ev3R2_L4JmI",
   "subscriberSnippet": {
    "title": "Kortney W",
    "description": "",
    "channelId": "UC33FFHTxOZ6NRZAp9afsRBw",
    "thumbnails": {
     "default": {
      "url": "https://yt3.ggpht.com/-T6Sn1ur07bk/AAAAAAAAAAI/AAAAAAAAAAA/BSSSRckoD4k/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "medium": {
      "url": "https://yt3.ggpht.com/-T6Sn1ur07bk/AAAAAAAAAAI/AAAAAAAAAAA/BSSSRckoD4k/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "high": {
      "url": "https://yt3.ggpht.com/-T6Sn1ur07bk/AAAAAAAAAAI/AAAAAAAAAAA/BSSSRckoD4k/s800-c-k-no-mo-rj-c0xffffff/photo.jpg"
     }
    }
   }
  },
  {


   "kind": "youtube#subscription",
   "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/UVJds9Q4d24quS-sEG8Qw_3MBzU\"",
   "id": "gI5QI3teCs8unbR7__8oVg7KlRfOtWQYR70kXNkS4PY",
   "subscriberSnippet": {
    "title": "TheCorty",
    "description": "",
    "channelId": "UC-0O3PZ0VPNySP2bNFAPDIA",
    "thumbnails": {
     "default": {
      "url": "https://yt3.ggpht.com/-8C6KXmEqDho/AAAAAAAAAAI/AAAAAAAAAAA/1roVNa2yF0o/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "medium": {
      "url": "https://yt3.ggpht.com/-8C6KXmEqDho/AAAAAAAAAAI/AAAAAAAAAAA/1roVNa2yF0o/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "high": {
      "url": "https://yt3.ggpht.com/-8C6KXmEqDho/AAAAAAAAAAI/AAAAAAAAAAA/1roVNa2yF0o/s800-c-k-no-mo-rj-c0xffffff/photo.jpg"
     }
    }
   }
  }
 ]
}
  1. 这只有在您拥有频道的情况下才有效
  2. 它不会仅返回最新的所有订阅者。
  3. 您无法按日期对响应进行排序。
  4. 您可以测试此here,只需确保您验证了正确的频道