유튜브 리스트 가져오기 - yutyubeu liseuteu gajyeoogi

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div class="container"> <h2>Videos list</h2> <ul id="results"></ul> </div> <script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>; <script type="text/javascript"> var playlist = '유튜브 영상 고유번호'; ////www.youtube.com/watch?v=유튜브 영상 고유번호 //playlist만 원하는 재생목록에 따라 가져오면 됨 //maxResult는 50 이하 $(document).ready(function () { $.get( "//www.googleapis.com/youtube/v3/videos", { part: 'snippet', maxResults: 50, id: playlist, key: '유튜브API키' }, function (data) { var output; $.each(data.items, function (i, item) { console.log(item); vTitle = item.snippet.title; vId = item.snippet.channelId; vDe = item.snippet.description; vTh = item.snippet.channelTitle; vaaa = item.snippet.thumbnails.standard.url; output = '<li>' + vTitle + '<br>--videoid: ' + vId + '<br>--videodescription: ' + vDe + '<br>--videothumbnails: ' + vTh + '<br><img src ="' + vaaa + '"></li>'; /*output= '<li>'+vTitle+'<iframe src=\"//www.youtube.com/embed/'+vId+'\"></iframe></li>';*/ $("div").append(output); }) } ); }); </script> </body> </html>

(❀╹◡╹)

$api_key = 'api-key'; //my API key $channel_id = 'UC채널아이디'; //my channel ID $max_result = 10; $url = '//www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$channel_id.'&maxResults='.$max_result.'&key='.$api_key; $video_list = json_decode(file_get_contents($url),TRUE); foreach ($video_list['items'] as $item) { if (isset($item['id']['videoId'])) { echo '<div class=""> <iframe width="750" height="422" src="//www.youtube.com/embed/'.$item['id']['videoId'].'" frameborder="0" allowfullscreen></iframe> <h2>'. $item['snippet']['title'] .'</h2> </div>'; } }

or

$(function() { var el = ""; $.ajax({ type: "GET", url: "//www.googleapis.com/youtube/v3/search", data: { order:"date", part:"snippet", channelId:"UC채널아이디", key:"api_key", maxResults:10 }, success: function(data){ $.each(data.items, function(index, item) { el = '<div class="">'; el += '<iframe width="750" height="422" src="//www.youtube.com/embed/' + item.id.videoId + '" frameborder="0" allowfullscreen></iframe>'; el += '<h2>' + item.snippet.title + '</h2>'; el += '</div>'; $("body").append(el); }); }, error: function(response){ console.log("Request Failed"); } }); });

유투브 API KEY 발급 방법

//velog.io/@yhe228/Youtube-API%EB%A5%BC-%EC%9D%B4%EC%9A%A9%ED%95%B4-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EA%B0%80%EC%A0%B8%EC%98%A4%EA%B8%B0

Youtube API key 발급받기

새로운 프로젝트를 만든다구글 (Youtube) API 사용 (사용설정, KEY 발급, 테스트 )

velog.io

  1. //console.developers.google.com 에 접속 한다

  2. 새로운 프로젝트를 만든다

  3. 새로만든 프로젝트를 선택하고 라이브러리 메뉴를 클릭한다

  4. 검색창에 youtube를 검색하고, youtube data API v3을 누른 후 사용설정 버튼을 클릭한다

  5. 사용자 인증 정보 만들기 버튼을 클릭

  6. 아래와 같이 설정해주고 어떤 사용자 인증 정보가 필요한가요? 버튼을 누르고 다음화면에서 완료 버튼을 눌러준다.

API key가 발급되었다.

======================================================

api 사용할 경우 할당량 문제가 있어서 다른 방법 검색

api 사용없이 가져오는 방법

<?php $url = "//www.youtube.com/feeds/videos.xml?channel_id=채널ID"; $curl_connection = curl_init($url); curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl_connection, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); $result = curl_exec($curl_connection); curl_close($curl_connection); $video_list = simplexml_load_string($result); for ($i=0; $i<4; $i++) { $youtube_id = explode(":", $video_list->entry[$i]->id)[2]; $youtube_url = '//www.youtube.com/watch?v='.$youtube_id; $youtube_src = '//i4.ytimg.com/vi/'.$youtube_id.'/hqdefault.jpg'; }

Toplist

최신 우편물

태그