Search code examples
pythongoogle-apiyoutube-apiyoutube-data-api

Youtube API - how can I exclude unlisted videos?


I'm using google api client to call YouTube Data and YouTube Analytics APIs and get video stats. I'm authenticated as the owner of the channel I am querying.

I am interested in only getting the public videos uploaded in the channel. I first query the YouTube Data API to get the list of videos in the uploads playlist and once I have the list of video ids I call the youtube Analytics API for each video and get the stats I need.

The problem I'm having is that when I list all videos in the uploads playlist I get hundreds of thousands (!!!) of unlisted videos, which I don't need.

I cannot afford to download the entire list and then check status to keep only the public videos as the number is too big and I am reaching my daily quota. It would also be a very inefficient way to do it.

is there a way to list only videos with status public for a specific playlist?

This is the current method I use:

data = service.playlistItems().list(
    part="snippet,status",
    playlistId=playlistID,
    maxResults="50",
).execute() 

I couldn't find any in the youtube API documentation on how to achieve this.


Solution

  • Have you tried to use PlaylistItems endpoint by not being authenticated, but, instead, using only your API key parameter?

    I'm assuming here -- though cannot check it myself -- that when not authenticated, the endpoint response will contain only videos that are public.