How To Fetch Instagram Images Using HashTag

<php

$hashtag='Test_hastTag';

$result1 = fetchData("https://api.instagram.com/v1/tags/{$hashtag}/media/recent/?access_token={$accessToken}");
$result1 = json_decode($result1);
?>
<?php foreach ($result1->data as $post): ?>
<!-- Renders images. @Options (thumbnail,low_resoulution, high_resolution) -->
<a class="group" rel="group1" href="<?= $post->images->standard_resolution->url ?>"><img src="<?= $post->images->thumbnail->url ?>"></a>
<?php endforeach ?>

<?php

function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}

?>
You can use Instpic plugin in wordpress
Advertisements

How To Fetch Instagram Images Using Username

<?php

$username="Your InstaGram Username";



$accessToken = "Your Access Token";


$userid= GetUserID($username, $accessToken);

$result = fetchData("https://api.instagram.com/v1/users/{$userid}/media/recent/?access_token={$accessToken}");
$result = json_decode($result);
?>

<?php foreach ($result->data as $post): ?>
<!-- Renders images. @Options (thumbnail,low_resoulution, high_resolution) -->
<a class="group" rel="group1" href="<?= $post->images->standard_resolution->url ?>"><img src="<?= $post->images->thumbnail->url ?>"></a>
<?php endforeach ?>

<?php

function GetUserID($username, $access_token) {

$urlnew = "https://api.instagram.com/v1/users/search?q=" . $username . "&access_token=" . $access_token;

if($resultnew = json_decode(fetchData($urlnew), true)) {

return $resultnew['data'][0]['id'];

}

}

// Gets our data
function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}

?>
You can use Instpic plugin in wordpress