인스타그램의 사진들을 저희 사이트에서 노출시키고 싶어 api를 이용하려고 하는데요
현제 진행상황은 사진 불러오는것까지 잘 되고있습니다.
페이지를 열면 엑세스토큰을 발급받아야 되는데 그게 안되는것 같습니다.
일단 제가 만든 소스는 이렇습니다.
뭐가 문제일까요;;;;
Copy
<? $curl = curl_init("https://api.instagram.com/oauth/access_token"); curl_setopt($curl,CURLOPT_POST,true); curl_setopt($curl,CURLOPT_POSTFIELDS,array( 'client_id' => '', 'client_secret' => '', 'grant_type' => 'authorization_code', 'redirect_uri' => 'http://www.thewedd.com/include/aass.htm', 'code' => $_GET['code'] )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($curl); curl_close($curl); $result = json_decode($result,true); print_r( $result[access_token] ); ?><html> <head> <meta http-equiv="Content-Type" conent="text/html"; charset="euc-kr"> <title>.</title> <style type="text/css"> #instaPics { max-width: 1100px; overflow: hidden; } img {width:181px;height:181px} .insta-box { position: relative; width: 181px; height: 181px; float: left; margin: 2px; border: none; } .image-layer { overflow: hidden; width: 100%; height: 100%; } .image-layer img { max-width: 100%; } .caption-layer { display: none; position: absolute; top: 0; background: rgba(255,255,255,0.8); height: 100%; width: 100%; padding: 10px; box-sizing: border-box; font-size: 9px; color: #333; } .insta-likes { float: right; } </style> <script src='//code.jquery.com/jquery-1.11.0.min.js'></script> <script type="text/javascript"> jQuery(function($) { var tocken = "<?=$result[access_token]?>"; var count = "30"; $.ajax({ type: "GET", dataType: "jsonp", cache: false, url: "https://api.instagram.com/v1/users/self/media/recent/?access_token=" + tocken + "&count=" + count, success: function(response) { if ( response.data.length > 0 ) { for(var i = 0; i < response.data.length; i++) { var insta = '<div class="insta-box">'; insta += "<a target='_blank' href='" + response.data[i].link + "'>"; insta += "<div class'image-layer'>"; //insta += "<img src='" + response.data[i].images.thumbnail.url + "'>"; insta += '<img src="' + response.data[i].images.thumbnail.url + '">'; insta += "</div>"; //console.log(response.data[i].caption.text); if ( response.data[i].caption !== null ) { insta += "<div class='caption-layer'>"; if ( response.data[i].caption.text.length > 0 ) { insta += "<p class='insta-caption'>" + response.data[i].caption.text + "</p>" //내용 } insta += "<span class='insta-likes'>" + response.data[i].comments.count + "댓글 " + response.data[i].likes.count + " Likes</span>"; //comment=댓글, likes=좋아요 insta += "</div>"; } insta += "</a>"; insta += "</div>"; $("#instaPics").append(insta); } } $(".insta-box").hover(function(){ $(this).find(".caption-layer").css({"backbround" : "rgba(255,255,255,0.7)", "display":"block"}); }, function(){ $(this).find(".caption-layer").css({"display":"none"}); }); } }); }); </script> </head> <body> <div id="instaPics"></div> </body></html>
|
답변 2개
채택된 답변
+20 포인트
2017-09-01 (금) 12:37:02
print_r($result);
해보세여. 안된다면 액세스 권한이나 오류메세지가 나올겁니다.메세지 확인하시고 진행하면 될거같네여
2017-09-01 (금) 13:09:11
자기 본인 계정은 잘 되는데
다른 사람 계정으로 하면 안된다는 건가요??
일단 현재 개발자 사이트에 등록된 앱이 샌드박스인지 라이브 상태인지 확인해보시기 바랍니다.
답변을 작성하려면 로그인이 필요합니다.