如何使用 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.
相关文章