Youtube API - Extract video ID(Youtube API - 提取视频 ID)
问题描述
我正在编写允许用户输入 Youtube 视频 URL 的功能.我想从这些网址中提取视频 ID.
I am coding a functionality that allows users to enter a Youtube video URL. I would like to extract the video ID from these urls.
Youtube API 是否支持我传递链接并返回视频 ID 的某种功能.还是我必须自己解析字符串?
Does Youtube API support some kind of function where I pass the link and it gives the video ID in return. Or do I have to parse the string myself?
我正在使用 PHP ......我很感激这方面的任何指针/代码示例.
I am using PHP ... I would appreciate any pointers / code samples in this regard.
谢谢
推荐答案
这是一个使用正则表达式从 URL 中提取 youtube ID 的示例函数:
Here is an example function that uses a regular expression to extract the youtube ID from a URL:
采用来自类似的问题.
这不是您正在寻找的直接 API,但可能有帮助.Youtube 有一个 oembed 服务:
It's not directly the API you're looking for but probably helpful. Youtube has an oembed service:
它提供了更多关于 URL 的元信息:
Which provides some more meta-information about the URL:
但 ID 不是响应的直接部分.但是,它可能包含您要查找的信息,并且可能有助于验证 youtube 网址.
But the ID is not a direct part of the response. However it might contain the information you're looking for and it might be useful to validate the youtube URL.
这篇关于Youtube API - 提取视频 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!