Latest one video uploaded in youtube channel

869 Views Asked by At

I need to show the thumbnail of the latest video on my youtube channel on my website and add a link to that video. While using the API parameter date it's showing the first video in that channel. Instead of that, I need the last published video details how to solve this

This is what I used as I require only one last video

https://www.googleapis.com/youtube/v3/search?key=[key]&channelId=[channel-id]&part=snippet,id&order=relevance&maxResults=1

2

There are 2 best solutions below

2
VC.One On

(option 1)

You could try replacing order=relevance with order=date

try:

https://www.googleapis.com/youtube/v3/search?key=[key]&channelId=[channel-id]&part=snippet,id&order=date&maxResults=1

(option 2)

You could also try using publishedAfter command (which takes a year-month-day format).
Example: publishedAfter=2019-03-25T00:00:00Z (because yesterday was March 25th).

try:

https://www.googleapis.com/youtube/v3/search?key=[key]&channelId=[channel-id]&part=snippet,id&publishedAfter=2019-03-25T00:00:00Z&order=date&maxResults=1

(option 3)

Use your programming language to fetch / read the HTML source-code of the channel's uploads page. The first thumbnail listed after gridVideoRenderer is the latest, along with relevant URL.

Example steps:

1) Go to user's uploads page and use "view source" option to see the HTML text (source code).
This text is what your programming language should show you when you http request the link of the channel's uploads.

https://www.youtube.com/user/MARVEL/videos

2) After acquiring (or viewing) the source code

  • From there find position of the word gridVideoRenderer.

  • Then starting after position, now find the first occurence of word "url":".

  • That is the URL. Extract manually by hand or write code to do it automatically.
    PS: Replace any unicode in the link, like \u0026 with &.

https://i.ytimg.com/vi/QuP7V2gKgPI/hqdefault.jpg?sqp=-oaymwEZCPYBEIoBSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLDBeSfAIiCdLDKtA8h2G-AZqk-xhQ

0
MTOakey On

I tried "option 1" with my own Key, and got the correct response as far as which "video" from the "Channel" - NO THUMBNAILs, just references to it/them, code follows:

{
  "kind": "youtube#searchListResponse",
  "etag": "EymHvUd1w4o13UcSUT0C9YINu3o",
  "nextPageToken": "CAEQAA",
  "regionCode": "US",
  "pageInfo": {
    "totalResults": 181,
    "resultsPerPage": 1
  },
  "items": [
    {
      "kind": "youtube#searchResult",
      "etag": "23QGL4Y9Du8EXMntX5ZNdr1F7_k",
      "id": {
        "kind": "youtube#video",
        "videoId": "RRQjUvoSuKU"
      },
      "snippet": {
        "publishedAt": "2022-11-13T15:09:07Z",
        "channelId": "UCbhMYK2QQXgHjgnMN3zegRQ",
        "title": "All Things Closely",
        "description": "Luke 1:1-4.",
        "thumbnails": {
          "default": {
            "url": "https://i.ytimg.com/vi/RRQjUvoSuKU/default.jpg",
            "width": 120,
            "height": 90
          },
          "medium": {
            "url": "https://i.ytimg.com/vi/RRQjUvoSuKU/mqdefault.jpg",
            "width": 320,
            "height": 180
          },
          "high": {
            "url": "https://i.ytimg.com/vi/RRQjUvoSuKU/hqdefault.jpg",
            "width": 480,
            "height": 360
          }
        },
        "channelTitle": "Restoration Church Homestead",
        "liveBroadcastContent": "none",
        "publishTime": "2022-11-13T15:09:07Z"
      }
    }
  ]
}

THAT's all that showed on a browser page, no Thumbnails-just code, but could not figure out how to get any code in the string to PLAY that video ... any ideas? I would love to just have it as a LINK rather than any other scripts loaded on the server. I'm missing something, probably simple I bet, to get the returned video related to the data to play.