인스타그램 연동
페이지 정보
작성자 서방님 댓글 0건 조회 352회 작성일 19-01-10 13:19본문
<?php
function getFromUrl($url, $method = 'GET')
{
// Initialize
$info = parse_url($url);
$req = '';
$data = '';
$line = '';
$agent = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)';
$linebreak = "\r\n";
$headPassed = false;
// Setting Protocol
switch($info['scheme'] = strtoupper($info['scheme']))
{
case 'HTTP':
$info['port'] = 80;
break;
case 'HTTPS':
$info['ssl'] = 'ssl://';
$info['port'] = 443;
break;
default:
return false;
}
// Setting Path
if(!$info['path'])
{
$info['path'] = '/';
}
// Setting Request Header
switch($method = strtoupper($method))
{
case 'GET':
if($info['query'])
{
$info['path'] .= '?' . $info['query'];
}
$req .= 'GET ' . $info['path'] . ' HTTP/1.1' . $linebreak;
$req .= 'Host: ' . $info['host'] . $linebreak;
$req .= 'User-Agent: ' . $agent . $linebreak;
$req .= 'Referer: ' . $url . $linebreak;
$req .= 'Connection: Close' . $linebreak . $linebreak;
break;
case 'POST':
$req .= 'POST ' . $info['path'] . ' HTTP/1.1' . $linebreak;
$req .= 'Host: ' . $info['host'] . $linebreak;
$req .= 'User-Agent: ' . $agent . $linebreak;
$req .= 'Referer: ' . $url . $linebreak;
$req .= 'Content-Type: application/x-www-form-urlencoded'.$linebreak;
$req .= 'Content-Length: '. strlen($info['query']) . $linebreak;
$req .= 'Connection: Close' . $linebreak . $linebreak;
$req .= $info['query'];
break;
}
// Socket Open
$fsock = @fsockopen($info['ssl'] . $info['host'], $info['port']);
if ($fsock)
{
fwrite($fsock, $req);
while(!feof($fsock))
{
$line = fgets($fsock, 128);
if($line == "\r\n" && !$headPassed)
{
$headPassed = true;
continue;
}
if($headPassed)
{
$data .= $line;
}
}
fclose($fsock);
}
return $data;
}
$client_id="b7a*************"; // 클라이언트 ID
$access_token = "25888*************"; // 액세스 토큰
$url = "https://api.instagram.com/v1/users/self/media/recent?client_id=".$client_id."&access_token=".$access_token."&count=10";
$_source = getFromUrl($url);
$_data=json_decode($_source);
$json=$_data->data;
foreach($json as $data) {
echo "<div style=\"float:left;margin:5px;\"><a href=\"".$data->link."\" target=\"_blank\"><img src=\"".$data->images->thumbnail->url."\" class=\"image-style1 respond-img\"></a></div>";
}
?>
댓글목록
등록된 댓글이 없습니다.
