2017-02-03 42 views

回答

0

從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" 
} 
0

根據你問過什麼,這將是最簡單的方法:

$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
  • 高度
  • author_url
  • thumbnail_url
  • AUTHOR_NAME
  • 版本

希望這是你問什麼。

相關問題