-
Notifications
You must be signed in to change notification settings - Fork 52
YouTube API Notes
A place to note things about the YouTube API that I've found.
Given other undocumented limits it was surprising that you are able to retrieve all 11,000,000 comments from a single video given your project has to quota to do so. With a maximum of 100 per page, and 1 quota per request, would approximately eat up at least 110,000 quota units not counting reply threads.
https://www.youtube.com/watch?v=jNQXAC9IVRw
{
"viewCount": "194562166",
"likeCount": "9583686",
"dislikeCount": "214760",
"favoriteCount": "0",
"commentCount": "10934205"
}
There is an undocumented limit for search results. Despite the total results being shown as 1,000,000 or some other high number, you at most can get only around 750 total or 15 pages of results from any search. On the last page of actual results the nextPageToken
will be omitted.
{
"kind": "youtube#searchListResponse",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 50
}
}
There is an undocumented limit of 20,000 videos you can retrieve from any playlist (channel uploads and otherwise) with a YouTube API key. This doesn't mean that channels can't upload more than 20k videos, it means you just can't retrieve more than 20k via the api. For example, the CNN channel has more than 150k videos.
However, playlists other than the uploads playlist can only have 5,000 videos in them total. Likes, favorites, and any other created playlist.
There is a basic way to determine when comments, views, and likes/dislikes have been disabled.
Querying the part statistics
in videos.list
when...
-
viewCount
is missing then views are disabled -
likeCount
is missing then likes are disabled -
commentCount
is missing then comments are disabled
There are multiple factors and states for 'comments disabled'.
State | Comments in Interface | Comments in API |
---|---|---|
video.statistics.commentCount missing |
Comments are turned off | error.reason: "commentsDisabled" |
video.contentDetails.madeForKids == true |
Comments are turned off |
error.reason: "commentsDisabled" This will be the case even though there may be numbers in commentCount for older videos. |
video.contentDetails.regionRestriction your country is blocked |
Comments are turned off | Comments can be queried regardless of your country even when blocked worldwide (249). |
video.snippet.title ends with " - Topic" and video.snippet.description contains "Auto-generated by YouTube." |
Comments are turned off |
error.reason: "commentsDisabled" This will be the case even though there may be numbers in commentCount for older videos. |
video.status.privacyStatus == "private" or deleted |
Video unavailable | error.reason: "videoNotFound" |
Custom channel urls are not directly queryable in the API.
However, you can create a workaround that is described in more detail in issue #1.
Basically you can match up the url value with a customUrl
property on channels.
You may also workaround by grabbing the channel webpage and extracting the meta og:url property. In client side JS, a cors proxy is required to do this.