总结果计数与 YouTube v3 搜索 API 中返回的实际结果不匹配



我们正在使用youtube V3搜索API。我们在" TotalResults"中变得不匹配。计数和响应中返回的项目列表。项目字段。我要求在请求中提供50个视频。返回的响应显示TotalResults数为65,但响应有效载荷只有3个视频。

api:www.googleapis.com/youtube/v3/search/list

请求有效载荷

{key=API_KEY, maxResults=50, order=date, part=snippet, publishedAfter=2017-03-20T23:59:59.999-04:00, publishedBefore=2017-04-19T23:59:59.001-04:00, q=( ( "Wood Mackenzie" OR "Wood Mac" OR Woodmac OR @woodmackenzie ) AND NOT (fleetwood OR "fleet wood" OR 9WoodMac ) )  , type=video}

响应有效载荷

{
 "kind": "youtube#searchListResponse",
 "etag": ""m2yskBQFythfE4irbTIeOgYYfBU/HTW4WQODZeERIv51VrRfOhir8dg"",
 "nextPageToken": "CDIQAA",
 "regionCode": "US",
 "pageInfo": {
  "totalResults": 65,
  "resultsPerPage": 50
 },
 "items": [
  {
   "kind": "youtube#searchResult",
   "etag": ""m2yskBQFythfE4irbTIeOgYYfBU/lnNNrToZHGTehIEJ6bvEx5RZMo4"",
   "id": {
    "kind": "youtube#video",
    "videoId": "obzlB21t904"
   },
   "snippet": {
    "publishedAt": "2017-04-14T11:38:08.000Z",
    "channelId": "UC60Sa1LQjgy_a-K8ThN4eQw",
    "title": "Fleet wood mac Live at Leeds",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/obzlB21t904/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/obzlB21t904/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/obzlB21t904/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "KEVIN MARSHALL",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": ""m2yskBQFythfE4irbTIeOgYYfBU/uYuuTAL3vtnFI1WOYjth0cso2Xo"",
   "id": {
    "kind": "youtube#video",
    "videoId": "gHAn0SbwKMg"
   },
   "snippet": {
    "publishedAt": "2017-04-06T22:17:31.000Z",
    "channelId": "UC3_MxBSSbmGznoSTgoBQ7_w",
    "title": "Beat Club: British Invasion 60's, Pt-2; Animals-Move-Fleet Wood Mac-J.Mayall-Who-Pacemakers-Kinks",
    "description": "Eric Burdon & Animals: C.C. Rider 0:01 The Move: Wild Tiger Woman 3:55 Fleet Wood Mac: Dragonfly 6:26 John Mayall: My Pretty Girl 9:47 Thunderclap ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/gHAn0SbwKMg/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/gHAn0SbwKMg/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/gHAn0SbwKMg/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "ROCK&POPS1_koba",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": ""m2yskBQFythfE4irbTIeOgYYfBU/tapelxOG4Q3gZRJCR2qaVdt-ZO8"",
   "id": {
    "kind": "youtube#video",
    "videoId": "5GvLbFBdcF4"
   },
   "snippet": {
    "publishedAt": "2017-04-02T04:48:47.000Z",
    "channelId": "UC6fn383TI1HVDYW4dSEIogQ",
    "title": ""Dreams" by fleet wood mac (vocal cover)",
    "description": "I do not own this song. I do not make a profit off of this song. It belongs to the person(s) who wrote it. Please subscribe and comment below any suggestions?!",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/5GvLbFBdcF4/default.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/5GvLbFBdcF4/mqdefault.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/5GvLbFBdcF4/hqdefault.jpg",
      "width": 480,
      "height": 360
     }
    },
    "channelTitle": "Musikallitee",
    "liveBroadcastContent": "none"
   }
  }
 ]
}

,如文档本身所述, totalResults是:

整数

结果集中的结果总数。请注意,该值是一个近似值,可能不代表确切的值。此外,最大值为1,000,000。

您不应使用此值来创建分页链接。而是使用 nextPagetoken prevPagetoken 属性值确定是否显示分页链接。

该值只是近似/估计值,但不对返回的items总数的确切值。我已经用与您相同的细节测试了API,并且值往往会从636465

变化。

众多,您的代码没有错。这只是预期的行为。不幸的是,在任何地方都没有在任何地方陈述totalResults的价值基于或最佳使用的位置。最好进行不依赖此参数的实现。

相关内容

  • 没有找到相关文章

最新更新