Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use instagram api to fetch image with certain hashtag?

I am learning the instagram api to fetch certain hashtag image into my website recently.

After searching on the webs for a very long time I coundnt find any workable code for it.

Anyone can help?

Thanks!

like image 787
youaremysunshine Avatar asked Aug 27 '13 06:08

youaremysunshine


2 Answers

If you only need to display the images base on a tag, then there is not to include the wrapper class "instagram.class.php". As the Media & Tag Endpoints in Instagram API do not require authentication. You can use the following curl based function to retrieve results based on your tag.

function callInstagram($url)
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2
));

$result = curl_exec($ch);
curl_close($ch);
return $result;
}

$tag = 'YOUR_TAG_HERE';
$client_id = "YOUR_CLIENT_ID";

$url = 'https://api.instagram.com/v1/tags/'.$tag.'/media/recent?client_id='.$client_id;

$inst_stream = callInstagram($url);
$results = json_decode($inst_stream, true);

//Now parse through the $results array to display your results... 
foreach($results['data'] as $item){
    $image_link = $item['images']['low_resolution']['url'];
    echo '<img src="'.$image_link.'" />';
}
like image 55
Ismail Altunören Avatar answered Nov 15 '22 22:11

Ismail Altunören


You will need to use the API endpoint for getting a list of recently tagged media by the hashtag. It would look something like this to get media for the hashtag #superpickle

https://api.instagram.com/v1/tags/superpickle/media/recent

You will need to read the Instagram API documentation to learn more about it and how to register for a client ID. http://instagram.com/developer/

like image 45
Bill Rollins Avatar answered Nov 15 '22 22:11

Bill Rollins