Skylar Kennedy
Skylar Kennedy

Reputation: 367

How can I query YouTube API to get videos from auto-generated 'Topic' channels?

How can I input search parameters using the YouTube API so that I only get video ID's from topic channels? For instance, if I go to youtube.com and manually search "Hello Adele - Topic" I correctly get the song, 'Hello' from the 'Adele - Topic' channel as my first search result, https://www.youtube.com/watch?v=_WS9w10ygpU. However, if I perform the same query using the YouTube Data API, with the parameters:

part='snippet'
q='Hello Adele - Topic'

I won't get back the ID for the correct video. Is there any way to get this programmatically?

Upvotes: 2

Views: 1141

Answers (1)

abielita
abielita

Reputation: 13469

As stated in this thread, auto generated channels have no videos. They have only playlists with videos from other channels. So you have to look for playlists. You may check the sample request in this link.

Here's the URL sample of auto-generated Topic-based Id which grabs its playlist id:

GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=HC9m3exs6zk1U&fields=items%2Fid&key={YOUR_API_KEY}
//Outputs sample playlist Id: LP9m3exs6zk1U

Now here's the URL sample using that playlist Id to get the videos from the auto-generated Topic-based channel Id:

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=5&playlistId=LP9m3exs6zk1U&key={YOUR_API_KEY} 
//Outputs video data you want.

Hope this helps.

Upvotes: 2

Related Questions