YouTube API v3按频道ID搜索不会返回频道中的所有视频

时间:2015-06-24 19:29:25

标签: youtube youtube-api

查看此YouTube频道: https://www.youtube.com/channel/UCqiwZNUf9z9OrseJoVGWMMg

它包含8个视频。但是,以下请求仅返回5个视频(即使maxResults设置为10。

openingDate

您可以在JSON响应的第一部分中看到NSDate仅为5,而不是预期的8。

projects.sort({
  $0.openingDate!.compare($1.openingDate!) == NSComparisonResult.OrderedAscending
})

响应中的items数组只包含5个项目。我尝试了很多查询变体(包括关闭safeSearch),但它不会返回频道中的所有视频。

1 个答案:

答案 0 :(得分:1)

以下要求:

https://www.googleapis.com/youtube/v3/search?order=title&part=snippet&channelId=UCqiwZNUf9z9OrseJoVGWMMg&type=video&maxResults=10&key={YOUR_API_KEY}

得出以下结果:

 {
 "kind": "youtube#searchListResponse",
 "etag": "\"Y3xTLFF3RLtHXX85JBgzzgp2Enw/8i-meJV39_yfRucbNqwGwygIReU\"",
 "pageInfo": {
  "totalResults": 8,
  "resultsPerPage": 10
 }

尽管我可以告诉它与你发布的内容相同,但我没有指定safesearch参数但尝试了它,但正如你在返回的项目列表中看到的那样 - 它在频道上为我提供了所有视频。我不确定为什么API会对您造成错误,但它应该给出正确的结果。希望我可能会得到一些帮助。

PS:也尝试使用safesearch参数。我得到了你的结果(5个视频),其中包含“严格”和“无”的值,但是它给了我所有8个视频你所寻找的“中等”值我认为是默认值,因为它与我没有相同指定的参数。

 "items": [
  {
   "kind": "youtube#searchResult",
   "etag": "\"Y3xTLFF3RLtHXX85JBgzzgp2Enw/DlNXovOlstICaTGq9kp43GR9eBU\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "pcorjQxfwoA"
   },
   "snippet": {
    "publishedAt": "2015-04-08T16:59:38.000Z",
    "channelId": "UCqiwZNUf9z9OrseJoVGWMMg",
    "title": "EBB Retrofit Animation",
    "description": "This animation shows what is involved in completing a seismic retrofit on a house with a raised foundation and a 4 foot cripple wall.",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/pcorjQxfwoA/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/pcorjQxfwoA/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/pcorjQxfwoA/hqdefault.jpg"
     }
    },
    "channelTitle": "",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"Y3xTLFF3RLtHXX85JBgzzgp2Enw/0KLoeBTh2PYOW5CwXmq4Yzxhc-8\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "RV1IzHmSojI"
   },
   "snippet": {
    "publishedAt": "2015-04-08T17:00:17.000Z",
    "channelId": "UCqiwZNUf9z9OrseJoVGWMMg",
    "title": "EBB Retrofit HD",
    "description": "Watch Earthquake Brace + Bolt in action.",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/RV1IzHmSojI/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/RV1IzHmSojI/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/RV1IzHmSojI/hqdefault.jpg"
     }
    },
    "channelTitle": "",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"Y3xTLFF3RLtHXX85JBgzzgp2Enw/x74SevHlVYKeMKmn3O9Toaa33Lg\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "stpSa2rIbS8"
   },
   "snippet": {
    "publishedAt": "2015-04-08T17:33:29.000Z",
    "channelId": "UCqiwZNUf9z9OrseJoVGWMMg",
    "title": "FEMA Training Part 2",
    "description": "This video introduces the effect of earthquakes on houses, discusses past performance of houses in earthquakes, and introduces partial seismic rehabilitation...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/stpSa2rIbS8/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/stpSa2rIbS8/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/stpSa2rIbS8/hqdefault.jpg"
     }
    },
    "channelTitle": "",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"Y3xTLFF3RLtHXX85JBgzzgp2Enw/7sTYIalNOCQ6jn9X4VBCMphFzbk\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "jYll7dENSOo"
   },
   "snippet": {
    "publishedAt": "2015-04-08T17:23:02.000Z",
    "channelId": "UCqiwZNUf9z9OrseJoVGWMMg",
    "title": "FEMA Training Part 6",
    "description": "This video provides a brief overview of important concepts for identifying the load path in a structure, construction of shear walls, and correctly installin...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/jYll7dENSOo/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/jYll7dENSOo/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/jYll7dENSOo/hqdefault.jpg"
     }
    },
    "channelTitle": "",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"Y3xTLFF3RLtHXX85JBgzzgp2Enw/GyHVsiWjC3smdvRyhqM7k9TSAL4\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "KHNx0SluNBA"
   },
   "snippet": {
    "publishedAt": "2015-04-08T17:16:18.000Z",
    "channelId": "UCqiwZNUf9z9OrseJoVGWMMg",
    "title": "FEMA Training Part 4",
    "description": "This video clarifies that seismic rehabilitation work falls under the purview of the building code and building department, and gives a brief overview of code ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/KHNx0SluNBA/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/KHNx0SluNBA/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/KHNx0SluNBA/hqdefault.jpg"
     }
    },
    "channelTitle": "",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"Y3xTLFF3RLtHXX85JBgzzgp2Enw/qJoVONxqCG32ExIyXSOYwxgT4Q4\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "iaS1wIIrXbA"
   },
   "snippet": {
    "publishedAt": "2015-04-08T17:07:42.000Z",
    "channelId": "UCqiwZNUf9z9OrseJoVGWMMg",
    "title": "FEMA Training Part 1",
    "description": "This video introduces the training course, defines applicable terminology, and shows pictorially why seismic rehabilitation of houses is important.",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/iaS1wIIrXbA/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/iaS1wIIrXbA/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/iaS1wIIrXbA/hqdefault.jpg"
     }
    },
    "channelTitle": "",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"Y3xTLFF3RLtHXX85JBgzzgp2Enw/Ps3HC7X95sTlZ-sR3ZP3lHYhQSM\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "0hQpBJJofcs"
   },
   "snippet": {
    "publishedAt": "2015-04-08T17:31:56.000Z",
    "channelId": "UCqiwZNUf9z9OrseJoVGWMMg",
    "title": "FEMA Training Part 5",
    "description": "This video addresses application of prescriptive provisions for anchorage to foundation and cripple wall bracing contained in the International Existing Building ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/0hQpBJJofcs/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/0hQpBJJofcs/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/0hQpBJJofcs/hqdefault.jpg"
     }
    },
    "channelTitle": "",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"Y3xTLFF3RLtHXX85JBgzzgp2Enw/F1VbW4J8TYbRDZuDeotUfWoBi9M\"",
   "id": {
    "kind": "youtube#video",
    "videoId": "OLclXnCQD2k"
   },
   "snippet": {
    "publishedAt": "2015-04-08T17:12:49.000Z",
    "channelId": "UCqiwZNUf9z9OrseJoVGWMMg",
    "title": "FEMA Training Part 3",
    "description": "This video is the heart of the training course, introducing seismic vulnerabilities 'A through K' discussing how to identify vulnerable conditions, likely ea...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/OLclXnCQD2k/default.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/OLclXnCQD2k/mqdefault.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/vi/OLclXnCQD2k/hqdefault.jpg"
     }
    },
    "channelTitle": "",
    "liveBroadcastContent": "none"
   }
  }
 ]
}