获取最新发布的 YouTube 视频 URL [英] Get Latest Published YouTube Video URL

查看:76
本文介绍了获取最新发布的 YouTube 视频 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人能够帮助我解决我遇到的问题.

I hope someone might be able to help me with a problem I'm having.

目前在我们的网站上,我们有这个页面(http://driftgames.life/instagram)我们使用我们的 Instagram 生物链接 URL 来让人们导航到许多不同的链接.您还会注意到,我们将最新的 YouTube 视频嵌入到此页面中,以便于查找.

Currently on our website, we have this page (http://driftgames.life/instagram) which we use as our Instagram bio link URL to let people navigate to many different links. As you will also notice, we embed our latest YouTube video onto this page to make it easier to find.

我们遇到的问题是视频的嵌入是手动的,这意味着我们经常忘记更新此链接,这意味着它已过时.因此,我想要做的是尝试在 WordPress 插件中使用 YouTube API 来获取最新发布视频的 URL,在 cron 作业中检查它,然后将 URL 拉入我可以用于嵌入的短代码中.

The issue we're having is that the embed of the video is manual, meaning that oftentimes we forget to update this link meaning it's outdated. As such, what I want to do is try to use the YouTube API in a WordPress plugin to fetch the URL of the latest published video, check it on a cron job and then pull the URL into a shortcode that I can use for the embed.

它还需要是最后发布的视频,即最近在频道上公开的视频,因为我们每周发布 2 个视频,并且经常在后台安排视频.

It would also need to be the last published video, i.e. the one that was made public most recently on the channel, as we publish 2 videos a week and often have videos scheduled in the background.

有人对如何进行整个过程有任何想法吗?我以前从未创建过 WordPress 插件,也许没有必要,但我认为可能是为了将 URL 放入短代码中.

Does anyone have any ideas about how to go about this entire process? I've never created a WordPress plugin before, and maybe it's not necessary, but I thought it might be in order to put the URL into a shortcode.

提前致谢!

推荐答案

使用 YouTube 数据API 并选择PlaylistItems:列表 请求.

Use YouTube Data API and select the PlaylistItems: list request.

您需要:

  • 您想要获取最新发布视频的 YouTube 频道的 channel_id.
  • 获取 upload_playlist- 正如我在回答中所解释的.
  • 一个 API_KEY - 使用 YouTube 数据 API 所需.
  • The channel_id of the YouTube channel you want to get the lastest published video.
  • Get the upload_playlist- as I've explained in my answer.
  • An API_KEY - which is needed for use the YouTube Data API.

然后,您可以使用以下 URL 检索该频道中最新发布的视频:

Then, you can use this following URL for retrieve the latest published video in that channel:

网址:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&playlistId=UU1A_rSUOukzgb3XOJoZ9EMA&key=[YOUR_API_KEY]&fields=items(contentDetails(videoId%2CvideoPublishedAt)%2Csnippet(publishedAt%2Ctitle))&maxResults=1

地点:

  • playlistid:是 upload_playlist - 在这种情况下,UU1A_rSUOukzgb3XOJoZ9EMA -这是您在问题中发布的网站的 YouTube 频道.
  • key:您需要为使用 API 提供的 YouTube API 密钥.
  • maxResults:参数指定结果集中应返回的最大项目数.可接受的值为 0 到 50(含).默认值为 5.我在这里使用过:1.

结果如下:

{
  "items": [
    {
      "snippet": {
        "publishedAt": "2020-08-19T16:14:56Z",
        "title": "DRIFT MASTERS RIGA | BEHIND THE SCENES EXCLUSIVE!"
      },
      "contentDetails": {
        "videoId": "TAMNp524BS4",
        "videoPublishedAt": "2020-08-20T19:00:05Z"
      }
    }
  ]
}

这篇关于获取最新发布的 YouTube 视频 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆