Search code examples
youtube-apiyoutube-data-api

How can I list all videos of an YouTube channel including each video's view count


I'm using this link

https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId=[id]&maxResults=200&key=[key]

to get all videos from my channel. And I want to get every videos with view count. When I using part=statistics it returns an error.


Solution

  • Unfortunately, want you want to achieve is not possible: the Search.list API endpoint does not return a video's viewCount property.

    This behavior is in accordance with the official specs: the response of Search.list has its items property made of search resource objects. These objects does not provide much details about the respective API resources -- videos, channels or playlists.

    When you obtain, upon a Search.list invocation, a list of video IDs, you may well ask the Videos.list API endpoint to provide any metadata pertaining to those videos -- including the viewCount property.

    Do note that the Videos.list endpoint accepts its request parameter id to be a comma-separated list of at most 50 video IDs. Also note that (irrespective of the number of actual IDs passed on to id) the quota cost of one call to Videos.list is 1 unit (very cheap).