How list all videos from a YouTube channel? - youtube

https://www.googleapis.com/youtube/v3/channels?id=UC_x5XG1OV2P6uZZ5FSM9Ttw&part=snippet%2CcontentDetails%2Cstatistics&key={YOUR_API_KEY}
Using this API link, I get a list of videos from start but not all videos. I only get 300 to 500 videos.

This is a bit complicated. You have to make a few calls instead.
find the channel ID of the channel you want.
list playlists (youtube.channels.list set id to channelId and set part to contentDetails)
find the ID of the playlist with name uploads
list playlist items (youtube.playlistItems.list set playlistId and set part to snippet optionally set maxResults to 50)
Page through results using nextPageToken
Found this from here https://stackoverflow.com/a/27872244/975887
Hope this helps.

Related

YouTube Api v3: calculate youtube playlist length

How can i get a youtube playlist duration (the sum of all it's videos durations).
I used this endpoint to get the playlist videos :
https://youtube.googleapis.com/youtube/v3/videos?playlistId
and it's return the videos object with all videos ids, in this case i need to make an api call to get each video length with separate api call to :
https://youtube.googleapis.com/youtube/v3/videos
I searched for a solution for this and found that we can make a call to previous api with all ids each id with a query param ex. id=aaaaa&id=bbbbb, but i need to be the owner of these videos to make the request.
Is there any way to get all videos with one call and without being the owner of the videos ?

http request to get a list of playlist videos and titles

I can't seem to get a playlist list of videos and their titles. Here is the http request (one of many) I've tried:
https://www.googleapis.com/youtube/v3/search?&part=snippet&channelId=PLS3kdEFUhQD828Tj_46Si7Z8CdAgiVAPW&maxResults=50&key=(my key here)
I have the target channelId in, but I'm getting an invalid channel id error. I know it's the correct channelId though. Anyone know the proper request I should be using? I need to get a list of video ids and titles for each playlists I request.
Use playlistItems API to get the list of videos :
GET https://www.googleapis.com/youtube/v3/playlistItems
For your usecase :
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=PLS3kdEFUhQD828Tj_46Si7Z8CdAgiVAPW&key=YOUR_KEY
Try it in the explorer

Get all videos for a given user

I'm trying to find a way to retrieve all videos posted by a given user (eg: https://www.youtube.com/user/laliga/videos).
All the examples I've found online or the doc (https://developers.google.com/youtube/v3/docs/) seems to require either a playlist ID, channel ID or video ID.
Is there any way I can directly query the author's videos or am I forced to retrieve all playlists and then iterate over?
Thanks
You just need to map the user name to its channelID first via the YouTube API like so:
https://www.googleapis.com/youtube/v3/channels?forUsername=USER_NAME&part=id&key=API_KEY
Full docs: https://developers.google.com/youtube/v3/docs/channels/list
Then you can make a Videos:List call with that channelID to get the videos.
1)take your google key id and channel id and put inside below url
https://www.googleapis.com/youtube/v3/search?key=APIKEY&channelId=CHANNELID&part=snippet,id&order=date&maxResults=20
ex
https://www.googleapis.com/youtube/v3/search?key=adsjsdakhkjshd&channelId=sdahghsadhgj&part=snippet,id&order=date&maxResults=20

Can't get endAt on videos when calling

I'm using GET https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails%2Csnippet&maxResults=50&playlistId=PLFs4vir_WsTwwb2zqmtE2WTEFdc7AQHnc&key={YOUR_API_KEY}
This returns all data, but only videoId in each video contentDetails. Maybe I'm missing something here?
YouTube has removed the features that set start and end times to playlist items: here's a product forum post that details this (and indicates an official response from Google account reps):
https://productforums.google.com/forum/#!topic/youtube/Gipu_cCDScI
Since playlists can no longer set start/end times on its items, the API no longer delivers them.
Not an answer, but a workaround. You can retrieve a playlist and use videos list with up to 50 videoIds in the URL to retrieve each video duration.

How do I get a list of uploaded videos for a certain channel with the new YouTube Data API (V3)?

I am trying to get a list of video ids for all uploaded videos to a channel. I would also like to use the new version of the YouTube Data API (V3). How do I do this?
You have to get the upload playlist id to get each videos uploaded. To get that, you need to get the channel id. After you have the playlist id from the channel id, it is pretty simple. I have written out the steps for all three below.
Also, we offer PubSubHubBub which allows you to be alerted every time a new video is added to a channel, or you could use SUP (V2) to see which resources have changed before making the calls.
Instructions to get video ids for all uploaded videos for a channel in V3
Get the channel id for the channel you want (you probably only need to do this once, then you can save it)
Use search.list
Set type to channel
Set q to the name of the channel you want
Grab the channel id (something like this: "channelId": "UC0X2VuXXXXXXXXXXXXXXXX")
Get the playlist id for the channel uploads using the channel id from step 1 (you probably only need to do this once, then you can save it)
Use channels.list
Set id to UC0X2VuXXXXXXXXXXXXXXXX from step 1
Grab the uploads key from contentDetails (something like this: "uploads": "UU0XXXXXXXXXXXXXXXXXXXX")
Get the videos via the playlistitems in the playlist using the playlist id from step 2
Use playlistItems.list
Set playlistId to UU0XXXXXXXXXXXXXXXXXXXX from step 2
Go through each PlaylistItem and pull out the video id
In the meantime, there is a much easier way:
Use the channels.list
set forUsername = [CHANNELNAME]
set part = contentDetails
grab $data->items[0]->contentDetails->relatedPlaylists->uploads --> [PLAYLISTID]
Use playlistItems.list
Set playlistId = [PLAYLISTID] from step 1
Go through each PlaylistItem and pull out the video ids

Resources