【问题标题】:How to save youtube video url details like title,description,thumbnail,videoid in to mysql using php [closed]如何使用 php 将 youtube 视频 url 详细信息(如标题、描述、缩略图、videoid)保存到 mysql [关闭]
【发布时间】:2017-02-03 06:01:21
【问题描述】:

嗨,朋友们我正在尝试使用 php 将标题、描述、缩略图、视频 ID 等详细信息保存到 mysql 中,是否有任何参考。提交视频网址后,我需要将它们保存到我的数据库中..

谢谢

【问题讨论】:

  • 有一个名词叫报废..你需要了解一下
  • 好的,请在 github 中有任何参考
  • 谷歌Scrapping with php
  • developers.google.com/youtube/v3/getting-started你可以使用API​​。或者只是使用 PHP CURL 访问您的 youtube 网址并解析结果。 PHP CURL 将为您提供您需要使用 PHP 字符串函数提取所有信息的页面。查看抓取、字符串函数等

标签: php mysql youtube


【解决方案1】:

【讨论】:

  • 不错,工作正常,
【解决方案2】:

从 url 获取 id,即https://www.youtube.com/watch?v=DJJT0HLKtzA&list=PL10A80E048A9E16BA&index=11,这里的 id 是 DJJT0HLKtzA,您可以使用 $_GET 轻松获取。

其次,您需要使用 youtube 的 api 来获取您使用该 ID 后的数据。阅读更多关于它的信息here

或者更简单快捷的是使用 youtube 的 oEmbed(了解有关 oEmbed 的更多信息 here),即 https://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=DJJT0HLKtzA&format=json 在上一个示例中使用相同的 id 返回 JSON 数据:

{
   "version":"1.0",
   "thumbnail_url":"https:\/\/i.ytimg.com\/vi\/DJJT0HLKtzA\/hqdefault.jpg",
   "width":459,
   "author_url":"https:\/\/www.youtube.com\/user\/ThatVideoMakingKid",
   "provider_name":"YouTube",
   "type":"video",
   "provider_url":"https:\/\/www.youtube.com\/",
   "title":"Evanescence-Whisper Lyrics (Fallen)",
   "thumbnail_height":360,
   "thumbnail_width":480,
   "height":344,
   "author_name":"ThatVideoMakingKid",
   "html":"\u003ciframe width=\"459\" height=\"344\" src=\"https:\/\/www.youtube.com\/embed\/DJJT0HLKtzA?feature=oembed\" frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e"
}

【讨论】:

    【解决方案3】:

    根据您的要求,这将是最简单的方法:

    $request = json_decode(file_get_contents("https://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=AXnqkVTFUqY&format=json"));
    $author = $request->author_url;
    

    $request = json_decode(file_get_contents("https://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=AXnqkVTFUqY&format=json"), true);
    $author = $request['author_url'];
    

    那么我相信您知道如何将值添加到您的数据库中。

    这里提醒您可以获得哪些数据:

    • provider_name
    • thumbnail_width
    • thumbnail_height
    • 标题
    • html
    • 类型
    • provider_url
    • 身高
    • 作者网址
    • thumbnail_url
    • 作者姓名
    • 版本

    希望这是您所要求的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-10
      • 2012-06-09
      • 1970-01-01
      • 2012-05-20
      • 2014-04-20
      • 2011-10-12
      • 2011-06-06
      • 1970-01-01
      相关资源
      最近更新 更多