Get All Post Details Based on Tags

Fetch all post's that are tagged using API's without Authentication

techhawa-instagram-get-details-by-tags

Instagram is a social networking app made for sharing photos and videos from a smartphone. Similar to Facebook or Twitter, everyone who creates an Instagram account has a profile and a news feed.

This is a guide for web developers interested in integrating Instagram content on websites. In this tutorial i will guide how to get the details of Instagram user like name account-id, images, videos, followers, total-post and following.

Advantages of this method:

  • Get all post's that are tagged
  • Get all counts of likes and comments
  • Fetch post content.

GET ALL POST'S THAT ARE TAGGED:

  • First create a HTML file as userform.html and save the below code.

  • <!DOCTYPE html>
    <html lang="en">
    <head>
      <title>Techhawa - Get Instagram Tag Details</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <body>
    
    <div class="container">
      <h2>Techhawa - Instagram  Tag Form</h2>
      <form class="form-horizontal" action="Instagram-get-tag-details.php">
        <div class="form-group">
          <div class="col-sm-10">
            <input type="text" class="form-control" id="instagram-tag" placeholder="enter a tag name" name="instagram-tag">
          </div>
        </div>
        
      
        <div class="form-group">        
          <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-default">Submit</button>
          </div>
        </div>
      </form>
    </div>
    
    </body>
    </html>
    

  • Now create one PHP file as Instagram-user-detail.php and paste the below code.

  • <?php
    $tag_name = $_GET['instagram-tag'];
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://www.instagram.com/explore/tags/$tag_name/?__a=1",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "GET",
      CURLOPT_HTTPHEADER => array(
        "cache-control: no-cache",
        "content-type: application/json",
        "postman-token: cc3e7f07-b49c-4040-b511-c7f1af596954"
      ),
    ));
    
    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);
    
    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
    
    ?>
    

  • Now open userform.html file in the browser.
  • Enter some sample Instaram tag and click on submit button.
  • Note: In this tutorial, we use india as Instagram tag.


    instagram-tag-form
  • After submittion, you will see the JSON response of your Instagram user as shown below

  • instagram-hash-tag-result


Live Demo