Skip to content

Instantly share code, notes, and snippets.

@zainstar zainstar/index.php
Last active Dec 8, 2018

Embed
What would you like to do?
view media instagram
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
<title>Instagram</title>
<style>
.card.p-3 {
padding: 0!important;
margin-bottom: 15px;
margin-top: 15px;
}
.box-ig {
margin-top: 5em;
margin-bottom: 5em;
}
footer p {
margin-bottom: 0;
}
footer {
text-align: center;
padding: 15px;
background: #eee;
}
</style>
</head>
<body>
<?php
include_once 'instagram.php';
$instagram = new instagram();
$profile = $instagram->get_data()['profile'];
$data = $instagram->get_data()['data'];
?>
<div class="box-ig">
<?php if (!empty($profile)) { ?>
<div class="container">
<div class="col-sm-12 mb-3">
<div class="media">
<img class="mr-3 rounded-circle mr-3" src="<?php echo $profile['profile_picture']; ?>"
alt="<?php echo $profile['full_name']; ?>">
<div class="media-body">
<h5 class="mt-0">
<a href="<?php echo 'https://www.instagram.com/' . $profile['username']; ?>"> <?php echo $profile['username']; ?> </a>
</h5>
<p><?php echo $profile['counts']['followed_by'] ?> followers &nbsp;|&nbsp; <?php echo $profile['counts']['follows'] ?> following</p>
<b><?php echo $profile['full_name'] ?></b>
<p><?php echo $profile['bio'] ?></p>
</div>
</div>
</div>
</div>
<div class="container mt-3">
<div class="row">
<div class="card-columns">
<?php foreach ($data as $d) { ?>
<div class="card p-3">
<a href="<?php echo $d['link']; ?>">
<?php if ($d['carousel_media'] <> null) { ?>
<div id="c<?php echo $d['id']; ?>" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<?php for ($i = 0; $i < count($d['carousel_media']); $i++) { ?>
<li data-target="#c<?php echo $d['id']; ?>" data-slide-to="<?php echo $i; ?>"
class="<?php echo $i == 0 ? 'active' : ''; ?>"></li>
<?php } ?>
</ol>
<div class="carousel-inner">
<?php foreach ($d['carousel_media'] as $key => $c) { ?>
<div class="carousel-item <?php echo $key == 0 ? 'active' : ''; ?>">
<img class="d-block w-100" src="<?php echo $c['images']['low_resolution']['url'] ?>" alt="image">
</div>
<?php } ?>
</div>
<a class="carousel-control-prev" href="#c<?php echo $d['id']; ?>" role="button"
data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#c<?php echo $d['id']; ?>" role="button"
data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<?php } else { ?>
<img class="card-img-top w-100" src="<?php echo $d['image']['low_resolution']['url']; ?>"
alt="image">
<?php } ?>
<div class="card-body">
<p class="card-text">
<?php echo $d['caption']; ?>
</p>
<p class="card-text"><i class="fa fa-comment-o"></i> <?php echo $d['comments'] ?> | <i
class="fa fa-heart-o"></i> <?php echo $d['likes']; ?></p>
<p class="card-text">
<small class="text-muted"><?php echo $d['created_time'] ?></small>
</p>
</div>
</a>
</div>
<?php } ?>
</div>
</div>
</div>
<?php } else { ?>
<div class="col-12">
<div class="alert alert-danger" role="alert">
The access_token provided is invalid
</div>
</div>
<?php } ?>
</div>
<footer>
<div class="container">
<p>By: <a href="https://share.web.id">Share</a></p>
</div>
</footer>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
</body>
</html>
<?php
class instagram
{
function curl($url, $token)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url . $token,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
return "cURL Error #:" . $err;
} else {
return json_decode($response, true);
}
}
function get_data()
{
$token = 'token instagram';
$url = 'https://api.instagram.com/v1/users/self/media/recent/?access_token=';
$url_profile = 'https://api.instagram.com/v1/users/self/?access_token=';
if (isset($this->curl($url, $token)['data'])) {
$ig = $this->curl($url, $token)['data'];
$profile = $this->curl($url_profile, $token)['data'];
$data = [];
foreach ($ig as $i) {
$data[] = [
'id' => $i['id'],
'image' => $i['images'],
'carousel_media' => !empty($i['carousel_media']) ? $i['carousel_media'] : null,
'videos' => !empty($i['videos']) ? $i['videos'] : null,
'caption' => !empty($i['caption']['text']) ? $i['caption']['text'] : null,
'likes' => $i['likes']['count'],
'comments' => $i['comments']['count'],
'link' => $i['link'],
'tags' => $i['tags'],
'created_time' => date('d-M-Y H:i:s', $i['created_time'])
];
}
return [
'profile' => $profile,
'data' => $data
];
}
}
}
@zainstar

This comment has been minimized.

Copy link
Owner Author

commented Aug 25, 2018

Masukan token instagram di:

=> instagram.php line 33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.