PHP function to get instagram images by hashtag without API

<?php

function callInstaFunction($hashtag , $limit = 4) {

    $baseUrl = 'https://www.instagram.com/explore/tags/'. $hashtag .'/?__a=1';
    $url = $baseUrl;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($ch);

    curl_close($ch);

    $instagram_hastags = json_decode($result , true);

    $edges = $instagram_hastags['graphql']['hashtag']['edge_hashtag_to_media']['edges'];

    $list_of_images = array();

    foreach($edges as $key=&gt;$edge) {

        if($key == $limit) break;

        $list_of_images[$key]['src'] =  $edge['node']['thumbnail_src'];
        $list_of_images[$key]['caption'] =  $edge['node']['edge_media_to_caption']['edges'][0]['node']['text'];
        $list_of_images[$key]['href'] =  formInstaURL($edge['node']['shortcode']);

   
    }
    return $list_of_images;
}
?&gt;

Comments

  1. Will this no longer be usable from march 31? Is there an official documentation?

    ReplyDelete

Post a Comment

Popular Posts