如何验证 YouTube 视频 ID? [英] How to validate youtube video ids?

查看:41
本文介绍了如何验证 YouTube 视频 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在访问 Youtube API 之前验证在我的网站之一的 URL 中提交的 youtube 视频 ID,但我不知道此类 ID 中允许的字符是什么.我看到网上有人猜测它可以包含数字和字符,但我还没有看到这些视频 ID 的官方规范.

I want to validate youtube video ids sbumitted in the URL to one of my sites before accessing the Youtube API, but I don't know what the allowed characters are in such an id. I see people on the net guessing it can contain numbers and characters, but I haven't yet seen an official specification of these video ids.

有吗?

推荐答案

参见 此主题 官方信息.

你可以点击这个:http://gdata.youtube.com/feeds/api/videos/VIDEO_ID(页面现在返回:不再可用".)

you can hit this: http://gdata.youtube.com/feeds/api/videos/VIDEO_ID (Page now returns: "No longer available".)

并根据响应确定视频是否有效

and determine if the video is valid based on response

您无法使用 RegEx 检查 ID 的有效性,因为并非所有字母数字值都是有效 ID.

There's no way you can check the validity of the ID with RegEx, since not all alpha-numeric values are valid ID's.

附言我很确定我在视频 ID 中看到了破折号"

p.s. i'm pretty sure i saw "dashes" in video ID's

p.p.s.下划线"也是一个有效字符:http://www.youtube.com/watch?v=nrGk0AuFd_9

p.p.s. "underscore" is a valid character also: http://www.youtube.com/watch?v=nrGk0AuFd_9

[a-zA-Z0-9_-]{11} 是正则表达式(来源),但即使正则表达式有效,也不能保证视频会在那里

[a-zA-Z0-9_-]{11} is the regex (source), but there's no guarantee that the video will be there even if regex is valid

这篇关于如何验证 YouTube 视频 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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