问题描述
如何使用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
检索特定视频条目似乎很有趣:如果您向这样的网址发送请求:
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上是否存在视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!