Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Youtube API 3 get latest videos

So I am trying to grab 10 latest videos from user uploads.

Now the only problem is that the only date visible in the playlistitems request is publishedAt which is the date when the video was uploaded - not the date of when it was made public, which makes a huge difference.

I noticed that I can grab the correct date via the video request, but it just does not seem to be the best place to do it.

Let me show you an example of what I am dealing with.

Let's take Maroon5 channel.

forUserName: Maroon5VEVO

GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=Maroon5VEVO&key={YOUR_API_KEY}

https://developers.google.com/youtube/v3/docs/channels/list#try-it

Here is where we grab the:

uploadsId: UUN1hnUccO4FD5WfM7ithXaw

So we can query:

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UUN1hnUccO4FD5WfM7ithXaw&maxResults=50&key={YOUR_API_KEY}

https://developers.google.com/youtube/v3/docs/playlistItems/list#try-it

and then we can have a look at some videos.

Let's grab the latest one. For me it is this one:

"title": "Maroon 5 - This Summer's Gonna Hurt Like A ... (Explicit)", "videoId": "Wa64gOwuIyE"

And most importantly :

"publishedAt": "2015-06-01T17:41:58.000Z",

Now let's grab more details of this video, by running this query:

GET https://www.googleapis.com/youtube/v3/videos?part=snippet&id=Wa64gOwuIyE&key={YOUR_API_KEY}

https://developers.google.com/youtube/v3/docs/videos/list#try-it

Here we get more detailed view with a date that is ... different !

"publishedAt": "2015-06-01T20:00:01.000Z",

That means that the publishedAt date in playlists is actually the date of the upload - not when the video was made public.

In our list of 10 latest items we want the LATEST published videos , and not latest uploaded vids.

If you know a way how to approach it , please share.

Here is my snippet for now (working with a wrong publishedAt date)

 $.get(
        "https://www.googleapis.com/youtube/v3/playlistItems",{
        part : 'snippet',
        maxResults : 10,
        playlistId : UPLOADS_PID,
        key: YOUR_API_KEY},
        function(data) {

            $.each( data.items, function(i, item ) {                

                (...)

            });
        }
    );
like image 855
Proqb Avatar asked Aug 18 '15 13:08

Proqb


People also ask

How do I find most recent videos on YouTube?

Save your time by seeing the recently uploaded videos by default on the YouTube home page. This extension will save your time by showing recently uploaded videos by default, when opening the YouTube home page. Normally you would have to find and click the "Recently uploaded" button manually.

What data can I get from YouTube API?

The API provides the ability to retrieve feeds related to videos, users, and playlists. It also provides the ability to manipulate these feeds, such as creating new playlists, adding videos as favorites, and sending messsages. The API is also able to upload videos.

Can you download videos using YouTube API?

YouTube Video Downloader API enables users to convert Video into MP4, MP3, M4A formats using one endpoint. Get various video qualities such as 144p, 360p, and 720p. Using this API you can download videos with or without audio.


Video Answer


1 Answers

I believe you can use /search endpoint. As you want to grab 10 latest videos from user uploads, you can use channel id instead of playlist id.

Request:

GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={CHANNEL_ID}&maxResults=10&order=date&type=video&key={YOUR_API_KEY} 
like image 164
Saumini Navaratnam Avatar answered Sep 21 '22 20:09

Saumini Navaratnam