doutang3760
2015-11-19 16:37 阅读 16
已采纳

从YouTube视频中获取标题并将其写入HTML / CSS

I'm not the best at web coding, I've only gotten into it recently for a quick project. I'm looking to pull the title from the YouTube video and store it in a variable to which I can write out. Ive never used PHP before, I'm experienced In Java and Python although I have no idea how to set it up on my website.

index.html:

<html>
  <link rel="stylesheet" type="text/css" href="style.css">  

  <iframe width="1" height="1" src="https://www.youtube.com/embed/videoseries?list=PLsVV8G4dmXyE2mSm3ZSz_AcNVduhw2ZwM&rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>   
</html>

style.css:

body {
background-image: url("http://i.imgur.com/z6fgaW8.png");
background-color: #cccccc;
background-size: 100% 100%;
background-repeat: no-repeat;
}

My videos are in a playlist, to clarify: id like to pull the title from the YouTube API and write this in the bottom left corner of the website.

My website does have PHP support, not sure about the others.

My Website

Please correct any errors ;D Thankyou!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongzhukuai8177 dongzhukuai8177 2015-11-19 16:48

    You can use this code

    $result = json_decode(file_get_contents(sprintf('http://www.youtube.com/oembed?url=%s&format=json', urlencode($url))));
    if ($result) {
        $title = $result->title;
        $html = $result->html;
        $thumbnail_url = $result->thumbnail_url;
        $height = $result->height;
        $width = $result->width;
        $thumbnail_width = $result->thumbnail_width;
        $thumbnail_height = $result->thumbnail_height;
    }
    
    点赞 评论 复制链接分享

相关推荐