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

后端 未结 14 1619
[愿得一人]
[愿得一人] 2020-11-27 06:40

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

14条回答
  •  感情败类
    2020-11-27 07:13

    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.

    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
    

    (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


    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.

提交回复
热议问题