Reputation: 2283
According to this I'm supposed to ask this question here
I'm trying to get the most recent uploads for a channel (ExplosmEntertainment). I'm calling a PlaylistItemsResource.ListRequest
(which has always worked) like this:
PlaylistItemsResource.ListRequest listRequest = service.PlaylistItems.List("snippet");
listRequest.PlaylistId = "UUWXCrItCF6ZgXrdozUS-Idw";
listRequest.MaxResults = 1;
PlaylistItemListResponse response = listRequest.Execute();
PlaylistItemSnippet newUploadDetails = response.Items.FirstOrDefault().Snippet;
The problem is that newUploadDetails
lists this video: https://www.youtube.com/watch?v=PSHg-U4s-6c as the most recent upload whereas if you visit the actual uploads playlist, it is this video: https://www.youtube.com/watch?v=FHK4N8QLtBQ .
As this code has always worked for me thus far, this seems to be a problem with this video and the API, but is there something I'm doing wrong?
Edit:
This channel uploaded a new video last night (8/24/17) and I modified my code to this:
PlaylistItemsResource.ListRequest listRequest = service.PlaylistItems.List("snippet");
listRequest.PlaylistId = "UUWXCrItCF6ZgXrdozUS-Idw";
listRequest.MaxResults = 5;
PlaylistItemListResponse response = listRequest.Execute();
List<PlaylistItem> fiveRecent = response.Items.ToList();
@paolo suggested that maybe the results were getting cached and that's what I was seeing but in my fiveRecent
list, the list is as follows:
So these results show that the response.Items
are not ordered by published date. And, unfortunately, there doesn't seem to be an OrderBy
parameter like there is with some of the other APIs and their list methods.
This is the same order that the API Explorer gives
It is very odd to me that this order doesn't match the order in the actual playlist on YouTube. Does anyone have any suggestions for a different way to get the most recently uploaded video?
Upvotes: 1
Views: 741
Reputation: 2538
It is very odd to me that this order doesn't match the order in the actual playlist on YouTube
Same here. One would definitively expect that.
Ok, when I do this:
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&fields=items/snippet/publishedAt%2Citems/snippet/position%2Citems/snippet/title&maxResults=5&playlistId=UUWXCrItCF6ZgXrdozUS-Idw&key=API_KEY HTTP/1.2
I get this:
{
"items": [
{
"snippet": {
"publishedAt": "2017-08-25T04:30:00.000Z",
"title": "Ow, My Dick: The Aftermath - A Cyanide & Happiness True Story",
"position": 0
},
"contentDetails": {
"videoId": "SxYyTOgWBDI"
}
},
{
"snippet": {
"publishedAt": "2017-08-22T05:00:00.000Z",
"title": "X-Ray - Cyanide & Happiness Minis",
"position": 1
},
"contentDetails": {
"videoId": "PSHg-U4s-6c"
}
},
{
"snippet": {
"publishedAt": "2017-08-14T05:00:00.000Z",
"title": "Explosm Presents: Channelate - Drinkin' Alone",
"position": 2
},
"contentDetails": {
"videoId": "e-cbR0JwgsA"
}
},
{
"snippet": {
"publishedAt": "2017-08-24T05:00:00.000Z",
"title": "High Noon - Cyanide & Happiness Shorts",
"position": 3
},
"contentDetails": {
"videoId": "FHK4N8QLtBQ"
}
},
{
"snippet": {
"publishedAt": "2017-08-17T05:00:01.000Z",
"title": "Final Words - Cyanide & Happiness Shorts",
"position": 4
},
"contentDetails": {
"videoId": "fczItbbB-OA"
}
}
]
}
The order and times are the same as you provided, just GMT instead of PDT. But this also shows that the items are ordered by position
- which in theory should of course be analogue to publishedAt
.
Since it's not, I suggest fetching the first few, say 10 or 15, items of the playlist and ordering these by date. Then pray that the actual latest video is among those first X positions. I really can't think of anything else here.
Upvotes: 2