Helping you build a better website
(and other interesting web stuff)

CSSHTMLJavaScriptjQueryMSSQLMySQLPHPSilvaTechnologiesWordpress
Silva Web Designs - Blog

How to get Instagram / Twitter followers count using JQuery Ajax?

In this article, we will show you how you can get the total Twitter and Instagram followers count using jQuery.

Twitter Followers Count

We can simply get the number of Twitter followers by using CDN widgets, so we are going to use the below CDN with the screen name ‘silvawebdesigns’.


https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=company_name

In the following example, you can see how it is work and how to get it. The only thing you need to change is the twitter_username variable to your Twitter handle.

HTML


<h3>Silva Web Designs has <span id="twitter-followers"></span> Twitter followers.</h3>

jQuery


var twitter_username = 'your_username';

$.ajax({
  url: "https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=" + twitter_username,
  dataType: 'jsonp',
  crossDomain: true
}).done(function(data) {
  $("#twitter-followers").text(data[0]['followers_count']);
});

See this JSFIDDLE for a working demo.

Instagram Followers Count

Once you have your token, you can update the code below code with your “token” variable:-

HTML


<h3>Silva Web Designs has <span id="instagram-followers"></span> Instagram followers.</h3>

jQuery

<code class="language-JS">
var token = 'api_key';

$.ajax({
  url: 'https://api.instagram.com/v1/users/self',
  dataType: 'jsonp',
  type: 'GET',
  data: {
    access_token: token
  },
  success: function(data) {
    var follows = data['data']['counts']['followed_by'];
    $("#instagram-followers").text(follows);
  },
  error: function(data) {
    console.log(data);
  }
});

Nathan da Silva - Profile

Posted by: Nathan da Silva

Nathan is the Founder of Silva Web Designs. He is passionate about web development, website design and basically anything digital related. His main expertise is with WordPress, Magento, Shopify as well of many other frameworks. Whether you need responsive design, SEO, speed optimisation or anything else in the world of digital then get in touch. If you would like to work with Nathan, simply drop him an email at [email protected]

It’s good to share

2 thoughts on “How to get Instagram / Twitter followers count using JQuery Ajax?

  1. This doesn’t seem to be working today in 2020. I checked your JS Fiddle and its not working there either. Are you able to update?

Join the discussion