Skip to content
Youths Forum Youths Forum Youths Forum

Tech Blogs & Programming Tutorials

Youths Forum Youths Forum Youths Forum

Tech Blogs & Programming Tutorials

  • Blog
  • News
  • Programming
    • PHP
    • JavaScript
    • JQuery
    • CSS
    • HTML
    • API
  • Stock Market Live
  • Automobiles
    • Cars
  • Gadgets
    • Phones
    • Android Phones

Categories

  • Artificial Intelligence (1)
  • Automobiles (12)
    • Cars (7)
  • Blog (104)
    • Poems (2)
    • Space (2)
  • Command (2)
  • Education (2)
  • Entertainment (4)
  • Gadgets (9)
    • Phones (8)
      • Android Phones (4)
  • HTML Templates (11)
  • IT Training Institutes (1)
  • Lifestyle (4)
  • News (188)
  • Others (23)
  • Programming (296)
    • API (16)
    • CSS (83)
    • Database (4)
    • Hosting (1)
    • HTML (37)
    • JavaScript (117)
      • JQuery (27)
      • ReactJS (7)
    • PHP (116)
  • Python (3)
  • recipes (1)
  • SEE Result (1)
  • Server (3)
  • Blog
  • News
  • Programming
    • PHP
    • JavaScript
    • JQuery
    • CSS
    • HTML
    • API
  • Stock Market Live
  • Automobiles
    • Cars
  • Gadgets
    • Phones
    • Android Phones
Close

Search

API

[Updated] Instagram API to fetch User Profile, Followers, Following

By Admin
January 23, 2022 2 Min Read
0

Have you gone through one of our video tutorial : Simple Instagram API that fetches User Profile, Followers, Following, Images, Posts, Likes , Shares using JavaScript for fetching Instagram User profile, followers, following and posts.

Most of the viewers were getting a CORS error in the script. So, we decided to give it a look and found out that Instagram have updated their security and not allowed public to access the API easily. We are now with the solution to this.

Here is the solution for this CORS error :

Now try the following source code :

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<style>
  .posts{
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    flex-wrap: wrap;
  }
  .like-comment{
    font-size: 10px;
    color:#333;
    padding-bottom: 40px;
    font-weight: bold;
  }
</style>
<div class="container" style="margin-top:20px;margin-bottom:20px;padding:50px;background-color:#ddd;">
  <div class="row">
    <div class="col-md-3">
      <img src="" class="profile-pic" style="border-radius:50%;">
    </div>
    <div class="col-md-9">
      <h2 class="username"></h2>
      <div class="row">
        <div class="col-md-4">
          <span class="number-of-posts"></span> posts
        </div>
        <div class="col-md-4">
          <span class="followers"></span> followers
        </div>
        <div class="col-md-4">
          <span class="following"></span> following
        </div>
      </div>
      <div class="row" style="margin-top:60px;">
        <h4 class="name"></h4>
      </div>
      <div class="row">
        <h4 class="biography"></h4>
      </div>
      <br><hr><br>
      <div class="row">
        <p>POSTS</p>
      </div>
      <div class="row posts"></div>
    </div>
  </div>
</div>
<script>

  function loadImage(element){
    var url = element.attr('src');
    p = url.split("/");
    t = '';
    for(let i=0;i<p.length;i++){
      if(i==2){
        t += p[i].replaceAll('-','--').replaceAll('.','-')+atob('LnRyYW5zbGF0ZS5nb29n')+'/';
      }else{
        if(i != p.length-1){
          t += p[i]+'/';
        }else{
          t += p[i];
        }
      }
    }
    element.attr('src',encodeURI(t));
  }


  function nFormatter(num){
    if(num >= 1000000000){
      return (num/1000000000).toFixed(1).replace(/\.0$/,'') + 'G';
    }
    if(num >= 1000000){
      return (num/1000000).toFixed(1).replace(/\.0$/,'') + 'M';
    }
    if(num >= 1000){
      return (num/1000).toFixed(1).replace(/\.0$/,'') + 'K';
    }
    return num;
  }
  $.ajax({
    url:"https://reeteshghimire.com.np/instagram-api/?user=<?php echo $_GET['user'];?>",
    type:'get',
    success:function(response){
      response = JSON.parse(response);
      $(".profile-pic").attr('src',response.graphql.user.profile_pic_url);
      $(".name").html(response.graphql.user.full_name);
      $(".biography").html(response.graphql.user.biography);
      $(".username").html(response.graphql.user.username);
      $(".number-of-posts").html(response.graphql.user.edge_owner_to_timeline_media.count);
      $(".followers").html(nFormatter(response.graphql.user.edge_followed_by.count));
      $(".following").html(nFormatter(response.graphql.user.edge_follow.count));
      posts = response.graphql.user.edge_owner_to_timeline_media.edges;
      posts_html = '';
      for(var i=0;i<posts.length;i++){
        url = posts[i].node.display_url;
        likes = posts[i].node.edge_liked_by.count;
        comments = posts[i].node.edge_media_to_comment.count;
        posts_html += '<div class="col-md-4 equal-height"><img style="min-height:50px;background-color:#fff;width:100%" src="'+url+'"><div class="row like-comment"><div class="col-md-6">'+nFormatter(likes)+' LIKES</div><div class="col-md-6">'+nFormatter(comments)+' COMMENTS</div></div></div>';
      }
      $(".posts").html(posts_html);
      $('img').each(function(){
        loadImage($(this));
      });
    }
  });
</script>

 

 

 

Tags:

Instagram
Author

Admin

Follow Me
Other Articles
Previous

Trek to Rara : Best Trek in Western Nepal

Next

A Complete Guide to Poonhill Trek, Annapurna Region

No Comment! Be the first one.

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Kamana Sewa Bikas Bank Calls 20th Annual General Meeting, Other Resolutions to be Passed Including 15% Cash Dividend
  • Preparations complete for ‘NADA Auto Show 2026’, parking arranged at two locations
  • Nepal Telecom’s 4G Service Launched in Badimalika, Easing Access for Pilgrims
  • Global Fintech Awards 2026: Nepal’s 5 Fintech Companies in International Competition
  • Samsung’s Monsoon Bonanza: Special Discounts and 24-Month EMI Facility on TVs, Refrigerators, and Washing Machines

Tags

adsense ai animate animation animation using HTML and CSS API blog calculator chatgpt Cryptocurrency CSS css animation design Email Facebook featured filemanager file manager free template google htaccess HTML image Instagram interview javascript JQuery jquery ui NADA AutoShow NADA Auto Show 2024 password PHP Progressive Web App PWA QR random react reactjs Rotate travel Twitter vpn youthforum youthsforum youtube

About Us

At Youths Forum, we are passionate about sharing knowledge that empowers students, educators, professionals, and technology enthusiasts.

Our Mission

Our mission is simple: to make technology and education accessible, understandable, and beneficial for everyone. We strive to create content that helps our readers learn new skills and stay updated with industry developments.

RSS RSS

  • Kamana Sewa Bikas Bank Calls 20th Annual General Meeting, Other Resolutions to be Passed Including 15% Cash Dividend Admin
  • Preparations complete for ‘NADA Auto Show 2026’, parking arranged at two locations Admin
  • Nepal Telecom’s 4G Service Launched in Badimalika, Easing Access for Pilgrims Admin

Quick Links

  • Stock Market Live
  • Parliament Election 2082
Copyright 2026 — Youths Forum. All rights reserved. Blogsy WordPress Theme