How can I retrieve YouTube video details from video URL using PHP?

前端 未结 9 706
南方客
南方客 2020-12-02 13:46

Using PHP, how can I get video information like title, description, thumbnail from a youtube video URL e.g.

http://www.youtube.com/watch?v=B4CRkpBGQzU
         


        
9条回答
  •  失恋的感觉
    2020-12-02 14:20

    This returns metadata about a video:

    http://www.youtube.com/oembed?url={videoUrlHere}&format=json

    Using your example, a call to:

    http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=B4CRkpBGQzU&format=json

    Returns the following, which you can digest and parse with PHP:

    {
        "provider_url": "http:\/\/www.youtube.com\/",
        "thumbnail_url": "http:\/\/i3.ytimg.com\/vi\/B4CRkpBGQzU\/hqdefault.jpg",
        "title": "Joan Osborne - One Of Us",
        "html": "\u003ciframe width=\"459\" height=\"344\" src=\"http:\/\/www.youtube.com\/embed\/B4CRkpBGQzU?fs=1\u0026feature=oembed\" frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e",
        "author_name": "jzsdhk",
        "height": 344,
        "thumbnail_width": 480,
        "width": 459,
        "version": "1.0",
        "author_url": "http:\/\/www.youtube.com\/user\/jzsdhk",
        "provider_name": "YouTube",
        "type": "video",
        "thumbnail_height": 360
    }
    

提交回复
热议问题