DEV Community

Cover image for 5 YouTube Data API traps I hit building a playlist manager
Sam Wootton
Sam Wootton

Posted on Edited on

5 YouTube Data API traps I hit building a playlist manager

I built TidyList, a web app for cleaning up big YouTube playlists, on the YouTube Data API v3. Most of it behaved as documented. These five didn't, and each one cost me.

1. Paging never ends

You page through a playlist with nextPageToken, and the docs suggest you stop when it's missing. On a 3,404-video playlist, YouTube got past the last page and kept going: every response came back with items: [] and a nextPageToken equal to the one I'd just sent. Forever. My loop ran past 500 pages before I noticed, at one unit of my daily API quota per page.

The fix is to keep every token you've requested and stop as soon as one repeats. While you're there, leave pageToken out completely on the first request. Sending it as an empty string gave me 404s on some playlists.

2. Liked videos is just "LL"

channels.list?part=contentDetails&mine=true gives you relatedPlaylists, with your uploads and your likes. Uploads comes back as UU plus your channel ID, so it's tempting to build the likes ID the same way. Don't. Likes is the literal string "LL". Build it yourself and you get a playlist that doesn't exist.

Use whatever the response gives you, and never construct an ID.

3. Updating a playlist wipes it

I wanted users to rename a playlist, so I sent playlists.update with the new title and description. It worked, and it quietly cleared the playlist's tags and default language too. playlists.update replaces the whole snippet, so anything you leave out is deleted.

Send the snippet you loaded, with only the fields you mean to change replaced. And if you're only changing visibility, part=status on its own is refused with 400 unexpectedPart. You still have to send the snippet, because its title is required.

4. Inserting at the top reverses your list

This one I did to myself. I insert videos at position: 0, so new additions land at the top of the target playlist. Copy ten videos one at a time in order and they arrive upside down.

The fix is to walk the set last-first. Each insert pushes the previous one down, and the playlist ends up in the original order.

5. channelTitle is the wrong channel

On a playlistItem, snippet.channelTitle looks like the channel that made the video. It isn't. It's the channel that added the video to the playlist, which on your own playlists is you. Every video in my app showed my own name as the creator.

The uploader is snippet.videoOwnerChannelTitle. It's missing for private and deleted videos, because YouTube strips the owner fields from those.


If your playlists are full of deleted, private and duplicate videos, that's what I built TidyList to fix: https://tidylist.video/help

Top comments (0)