How to load/list YouTube channel Videos?
Here we will see how we can load YouTube channel video in our website by using JSON.
There are two steps:
Query Channels to get the “uploads” Id. eg
1 | https://www.googleapis.com/youtube/v3/channels?id={channel Id}&key={API key}&part=contentDetails |
Use this “uploads” Id to query PlaylistItems to get the list of videos. eg
1 | https://www.googleapis.com/youtube/v3/playlistItems?playlistId={"uploads" Id}&key={API key}&part=snippet&maxResults=50 |
Now we will start this from scratch
STEP 1 (Get API Key):
We will get ‘API Key’ from Google Developer Console, you can find steps here : https://developers.google.com/youtube/v3/getting-started
STEP 2 (Get Channel ID):
Go to your YouTube Channel and copy your channel URL e.g. https://www.youtube.com/channel/XXXXXXXThs2cnXXX-dt
and your channel id is ‘XXXXXXXThs2cnXXX-dt‘.
STEP 3 :
Now replace {channel Id} with your channel id and API Key with your API Key
https://www.googleapis.com/youtube/v3/channels?id={channel Id}&key={API key}&part=contentDetails
to
https://www.googleapis.com/youtube/v3/channels?id=XXXXXXXThs2cnXXX-dt&key=XXXXXXXXXXXXXXXXXXX&part=contentDetails
Here you will get “uploads” Id to query Playlist Items e.g.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | { "kind": "youtube#channelListResponse", "etag": "XXXXXXXXXXXABiQXX", "pageInfo": { "totalResults": 1, "resultsPerPage": 5 }, "items": [ { "kind": "youtube#channel", "etag": "XXXXXXXXXXYmaRUXXXXXX", "id": "XXXXXhs2cnzpqc-rAXXX", "contentDetails": { "relatedPlaylists": { "likes": "", "uploads": "XXXXwEk6hThs2cnzXXXX" // this is upload id } } } ] } |
“uploads”: “XXXXwEk6hThs2cnzXXXX” is the upload id
STEP 4 :
Use this “uploads” Id to query PlaylistItems to get the list of videos. eg
1 | https://www.googleapis.com/youtube/v3/playlistItems?playlistId={"uploads" Id}&key={API key}&part=snippet&maxResults=50 |
Here you will get Palaylist in json Format.