如何使用 PHP 检查 YouTube 上是否存在视频? [英] How do I check if a video exists on YouTube, using PHP?

查看:21
本文介绍了如何使用 PHP 检查 YouTube 上是否存在视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 PHP 检查 YouTube 上是否存在视频?

How do I check if a video exists on YouTube, using PHP?

推荐答案

使用 Youtube 的 API 怎么样?
毕竟,这意味着使用一些官方文件,与解析一些 HTML 页面相比,更改的可能性较小.

What about using Youtube's API?
After all, that would mean using some official, which is less likely to change than going with parsing some HTML page.

有关详细信息:YouTube API 和工具 - 开发人员指南:PHP

For more information: YouTube APIs and Tools - Developer's Guide: PHP

检索特定视频条目似乎很有趣:如果您向这样的 URL 发送请求:

The Retrieving a specific video entry seems quite interesting: if you send a request to an URL like this one:

http://gdata.youtube.com/feeds/api/videos/videoID

(用视频的 ID 替换videoID",当然,在你的例子中是GeppLPQtihA"),如果视频有效,你会得到一些 ATOM 提要;如果不是,则为无效 ID"

(replacing "videoID" by the ID of the video, of course – "GeppLPQtihA" in your example), you'll get some ATOM feed if the video is valid; and "Invalid id" if it's not


而且,我坚持:这样,您依赖于文档化的 API,而不是依赖于今天存在但不能保证的某种行为.


And, I insist: this way, you rely on a documented API, and not on some kind of behavior that exists today, but is not guaranteed.

这篇关于如何使用 PHP 检查 YouTube 上是否存在视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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