Youtube api v3 cannot retrieve all videos from a channel

淺唱寂寞╮ 提交于 2020-01-23 13:26:44

问题


I am trying to use youtube data api to get all videos from a channel. But it didn't work for a particular channel. (It works for several other channels.)

As you can see from the screenshot, this channel has 135 videos.

However, I used playlistitems and search api, as below. They only return 9 videos. What is the problem here? Thanks.

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=UUhTMiw43iw4w-ggOEXmPtfg&key={YOUR_API_KEY} 

GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UChTMiw43iw4w-ggOEXmPtfg&maxResults=50&type=video&key={YOUR_API_KEY}

回答1:


Basically you're dealing with two different channels with the same title but this is acceptable because of the customUrls are different, here the details:

1. DharmaYogaCenter: UChTMiw43iw4w-ggOEXmPtfg - title: DharmaYogaCenter

GET https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails%2Cstatistics&id=UChTMiw43iw4w-ggOEXmPtfg&key={YOUR_API_KEY}

``` json 
{
    "title": "DharmaYogaCenter",
    "description": "We are a full yoga center located in Bremerton Washington.  We believe yoga and meditation is for everyone.  Stop by our Yoga Center and enjoy a blissful meditation, yoga class or just some good community.  We offer many free classes every month.  www.dharmayogacenter.net",
    "customUrl": "DharmaYogaCenter",
    "publishedAt": "2009-06-11T21:43:56.000Z",
    ...
    "relatedPlaylists": {
     "uploads": "UChTMiw43iw4w-ggOEXmPtfg",
    ...
    "videoCount": "9"
    ...
```

You can check there are only few videos in here: uploaded videos in channel UC8hnoz74NP5V5sxkuxXk2kA

"youtube#channel" "id": UChTMiw43iw4w-ggOEXmPtfg

GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=UChTMiw43iw4w-ggOEXmPtfg&key={YOUR_API_KEY} get the playlist id of channel's "uploads": "UUhTMiw43iw4w-ggOEXmPtfg"

uploads playlist: UUhTMiw43iw4w-ggOEXmPtfg "totalResults": 9

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=UUhTMiw43iw4w-ggOEXmPtfg&key={YOUR_API_KEY}

{
 "kind": "youtube#playlistItemListResponse",
 "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/yvjEzYc-CE8RBoXkFDTMPf_O1XM\"",
 "pageInfo": {
  "totalResults": 9,
  "resultsPerPage": 50
 },...

2. TheDharmaTube: UC8hnoz74NP5V5sxkuxXk2kA - title: DharmaYogaCenter

GET https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails%2Cstatistics&id=UC8hnoz74NP5V5sxkuxXk2kA&key={YOUR_API_KEY}

{ 
    "title": "DharmaYogaCenter",
    "description": "Be receptive",
    "customUrl": "TheDharmaTube",
    "publishedAt": "2011-02-24T22:54:31.000Z",
    ...
    "relatedPlaylists": {
     "uploads": "UU8hnoz74NP5V5sxkuxXk2kA",
    ...
    "videoCount": "142"

You can check there are a lot more videos in here: uploaded videos in channel UC8hnoz74NP5V5sxkuxXk2kA ..scroll down once opened to load all the videos

"youtube#channel" "id": UC8hnoz74NP5V5sxkuxXk2kA

GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=UC8hnoz74NP5V5sxkuxXk2kA&key={YOUR_API_KEY} get the playlist id of channel's "uploads": "UU8hnoz74NP5V5sxkuxXk2kA"

uploads playlist: UU8hnoz74NP5V5sxkuxXk2kA "totalResults": 142

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=UU8hnoz74NP5V5sxkuxXk2kA&key={YOUR_API_KEY} "totalResults": 142,

{
 "kind": "youtube#playlistItemListResponse",
 "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/jm3DhRxnqdMzu1DGtIoiLbpEFY4\"",
 "nextPageToken": "CDIQAA",
 "pageInfo": {
  "totalResults": 142,
  "resultsPerPage": 50
 },...


来源:https://stackoverflow.com/questions/37040885/youtube-api-v3-cannot-retrieve-all-videos-from-a-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!