php 부분


<?php

function CurlGet( $url ){


        $curlsession = curl_init ();

        curl_setopt($curlsession, CURLOPT_CUSTOMREQUEST, "GET");

        curl_setopt ($curlsession, CURLOPT_URL, $url);

        curl_setopt ($curlsession, CURLOPT_HTTPGET, TRUE);

        curl_setopt ($curlsession, CURLOPT_RETURNTRANSFER, 1);

        //curl_setopt($curlsession, CURLOPT_HTTPHEADER, $headers);

        $res = curl_exec ($curlsession);


        return $res;

    }

 $Chnelurl = 

'https://www.googleapis.com/youtube/v3/playlistItems?playlistId=재생목록ID&key=나의 KEY&part=snippet&fields=*&maxResults=50';

    $res = CurlGet($Chnelurl);


?>

---------------------------------------------------------------------------------------------

html 부분


<table>

<tr>

<th>img</th>

<th>title</th>

<th>ViewCount</th>

<th>regdate</th>

</tr>

<tbody id="getVideo"></tbody>

</table>

---------------------------------------------------------------------------------------------

script 부분


<script>

var div ;

$(function () {

var res = <?=$res?>;

var count = Object.keys(res.items).length;

var videoId, videoImg, videotitle, Viewurl, qwer;

for(var i = 0; i<count; i++){

  videotitle = res.items[i].snippet.title; 

  videoId = res.items[i].snippet.resourceId.videoId;

  videoImg = res.items[i].snippet.thumbnails.default.url;

  url = 'https://www.googleapis.com/youtube/v3/videos?id='+videoId+'&key=나의 KEY&part=statistics,snippet&fields=*';

ViewUrl(url,videoId, i);

$("#getVideo").append(

'<tr><td><img src="'+videoImg+'"></td><td><a href="http://www.youtube.com/watch?v='+videoId+'">'+videotitle+'</a></td><td id="countvideo_'+i+'"></td><td id="regdate_'+i+'"></td></tr>'

);

}

});

function ViewUrl(urls,vid,count){

$.ajax({

        url: urls,

        dataType: "json",

        success: function (data) {

console.log(data);

if(vid == data.items["0"].id){

var dataviews = data.items["0"].statistics.viewCount;

var regdate = data.items["0"].snippet.publishedAt;

var regdates = regdate.split('T');

$("#countvideo_"+count).html(dataviews + " view");

$("#regdate_"+count).html(regdates[0]);

}

},

 error:function(request,status,error){

        alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);

       }

    });

}


</script>

---------------------------------------------------------------------------------------------

ViewUrl.php


<?php

function CurlGet( $url ){


        $curlsession = curl_init ();

        curl_setopt($curlsession, CURLOPT_CUSTOMREQUEST, "GET");

        curl_setopt ($curlsession, CURLOPT_URL, $url);

        curl_setopt ($curlsession, CURLOPT_HTTPGET, TRUE);

        curl_setopt ($curlsession, CURLOPT_RETURNTRANSFER, 1);

        //curl_setopt($curlsession, CURLOPT_HTTPHEADER, $headers);

        $res1 = curl_exec ($curlsession);


        return $res1;

    }

$Viewurl = $_POST['url'];

 $res1 = CurlGet($Viewurl);

echo '<pre>'.$Viewurl.'</pre>';


?>


결과물 




'API' 카테고리의 다른 글

[GoogleCharts] ComboChart 예제  (0) 2017.07.21

select box 옵션 선택 시, 선택 된 값 스타일 변화


// selected 주기 위함

<?php

$selectBTS = "";

$selectTWICE = "";

if($_REQUEST['singsel'] == "BTS"){

$selectBTS = "selected";

}else if($_REQUEST['singsel'] == "TWICE"){

$selectTWICE = "selected";

}


?>


<!doctype html>

<html lang="en">

 <head>

  <meta charset="UTF-8">

<!-- style 주기 -->

  <style>

.register_account { color: #FF0000; background: white; }

option:not(:checked) { color: #000000; background: white; }

  </style>


 </head>

 <body>

  <select id="singsel">

<option value ="">가수들</option>

    <option value="BTS" <?=$selectBTS?>>BTS</option>

    <option value="TWICE" <?=$selectTWICE?>>TWICE</option>

  </select>

  

<script src="js/jquery-3.2.1.min.js" type="text/javascript"></script>

  <script>

$(function() {

// singsel 의 값이 있으면 class 값 주기

if($("#singsel").val()){

$("#singsel").addClass('register_account');

}


// singsel change 

$("#singsel").change(function() {

var singsel = $("#singsel").val();

if(singsel){

location.href="<?=$_SERVER['PHP_SELF']?>?singsel="+singsel;

}else{

location.href="<?=$_SERVER['PHP_SELF']?>";

}

});

});

  </script>

 </body>

</html>


결과


value 없을 때 

값 선택 전


값 선택 시 글씨 색 변경



'Javascript > JQuery' 카테고리의 다른 글

[JQuery] Append 이용한 Row 추가 삭제  (0) 2017.08.28


위에 데이터 차이가 많이 날 경우 , Y축에 보조축으로 같이 두고있을때, 

targetAxisIndex:1 을 하게 되면, 다음과 같이 나오게 된다.


결과 화면 


'API' 카테고리의 다른 글

[Youtube API] 유튜브 API통해 재생목록 및 View_count 출력  (0) 2017.08.02

+ Recent posts