Social Count Facebook, Twitter, Youtube, Google+, Instagram, Vimeo, Dribbble, Soundcloud with jQuery Ajax & PHP

Download the script Check the demo

Need to retreive the, Facebook Fans, Youtube subscribers, followers from Twitter (API 1.1), Dribbble, Vimeo, Instagram Souncloud and Google plus ? I made this script for that working with PHP, jQuery and Ajax and using cache to reduce the API limitation problems.

In this tutorial i will show how to install the script and make it work 😀

First of all, unzip the “” file into your directory for example Localhost/social-count/

In the index.php file we will setup our script

In this case we select all the 8 Social networks to retreive data from it, if you dont want to use one of them just delete the name of it from the code below:

var social_networks = [

Facebook, Youtube, Dribbble & Vimeo

Now we go to the social_count.php ,
For Facebook, Youtube, Dribbble and Vimeo We just need to put the page or the username for it

$facebook_page = 'google';  //
$youtube_channel = 'Apple'; //
$dribbble_username = 'Facebook';  //
$vimeo_username = 'royalhandmadecustoms'; //

For Twitter, Instagram, Google + and SoundCloud we have to create an application for each of them to get our access token
ps: After The update of the Twitter API to the 1.1 version we can’t retreive the twitter followers without having an access token


To create a twitter application go to and fill the form with givving a name for your app, a description, the link of your website domain, agree the Developer Rules and make submit


In your application details , you will find the Access token, Access token secret, Consumer key and the Consumer secret

Now, in the social_count.php complete the twitter settings.
for the username, put the username of the public user you want to retreive the followers count

$twitter_username = "amine_pv0"; //
$oauth_access_token = ""; 
$oauth_access_token_secret = "";
$consumer_key = "";
$consumer_secret = "";


Go to and create a new app


In the form make sure to give a name for your application and a description
For the “website” and the “OAuth redirect_uri” fill “http://Localhost/social-count/chnage the url with your domain

Now, we need to retreive the access token, change the adress below with your Client ID and Redirect Uri and open it in your browser

Then you will redirected to instagram app box, click on Authorize
By clicking on Authorize you will be redirected to
Save the acess token, we will need it

The last step in setting up the instagram, we need your user ID, for that, i found a website that make it really easy for that, so go the , write you username and get the User ID after submiting the form.

For now, we have the Instagram’s access token and our user ID, so change it in the social_count.php

$instagram_userID = '';
$instagram_accessToken = '';

Google +

For Google plus, we need and API Key, so right there in this link , create a new project by giving a name for it, then active the Google+ API


Then in the left menu, Go to API Access and copy the API key
Then you need the page id u want to retreive followers from it, by opening the page in the browser you can get it
example :
from this url our Page ID is +InterestingEngineering
it can be like this
so the page ID is 104477202728652698005

Now change the social_count.php with pageID and the API Key

$gplus_pageID = '';
$gplus_api_key = '';


Lets finish with the SoundCloud :) , so go to and give a new for your app, then complete the for with your website adress and copy the Client ID

Now lets come back to the social_count.php and put the username we want to retreive its folowers and the ClientID we got from the form

$soundcloud_username = '';
$soundcloud_clientID = '';

  • Colinch

    I got the following error:

    Error opening output file

    The only thing I did was commenting all services except for youtube in the index, and I filled in the apple user in the social_count.php as youtube user.

    • what apple user ?

      • Colinch

        Oh, like in the example; I named the youtube user “apple”. I hope we can fix this problem because this is exactly what I needed :) Should I post a copy of my code? (not here)

      • Colinch

        I think I fixed it, I had to create the cache file myself and set all rights with chmod. So for everyone having the same problem, that’s probably the solution.

  • Gianluca Del Re

    i try for facebook. I have one number ilikes and do myself. Not view nothing munbers on fans but i hope because do myself. i want saw because i don’t go on link on facebook created for count ” i likes”. I have inserted all files and in code php write ‘ VisuaspaceBacheca’ // Thanks, please responde me

    • usually there s (+/1) fan difference between the facebook and it API, and this code tutorial is working with the cache, so the count is stored in a file, then after a time it will make update (we use that cuz the limits of the api calls) , you can change your cache update ($expire = 300 ) 300 sec

      • Gianluca Del Re

        In the files for plugin to ownload there isn’t cache files.. i inserted all css and javascript jquery. i have linked file social_counter.php to page. I change th string inside in

        $facebook_page = ‘VisuaspaceBacheca’; //

        $youtube_channel = ”;

        $dribbble_username = ”;

        $vimeo_username = ”;

        • Gianluca Del Re

          and write in

          function facebook_fans($fb_page, $cache, $expire){

          $expire = time()-$expire;

          $facebookUrl = ‘’.$fb_page;

          $cache_data = FetchData($cache);

          Where there problem that not view fans

          • leave the $facebookUrl like it is “$facebookUrl = ‘’.$fb_page;”
            or “$facebookUrl = ‘’;”

  • Gianluca Del Re

    for second question i ask because i click on button only facebook for now and it don’t go to link Click on button but no t go to nothing link, as i do for go to link for my visititors

  • Gianluca Del Re

    I write but always don’t show number. maybe i will linked file in page plugin OAuth.php and twitteroauth.php because the page php are not linked to page.Thanks.and for view plugin go to

    • just follow the tuto, and make sure you include right the files

      • Gianluca Del Re

        i included all file and not count fans and write as say you. More if i inserted files php o auth ecc. i don’t saw. I checked for script php and the page exist and dont found counter. i try with other platform if the count started.Thanks

  • Gianluca Del Re

    sorry www.

  • Gianluca Del Re

    i try but facebook not started and i on’t saw that other social go right. Thanks and if not star i brings to plugin

    • Gianluca Del Re

      if you watch on <I try inserted also auth php and try if started. On difference beween exampl is bar gif not show.

  • ZONE7th

    thank you to the more posts that you have shared, it is very useful for me :)

  • anakontaa

    That’s a very nice tutorial. But i have some error when trying to use twitter, is it something i’m doing wrong?
    Fatal error: Call to undefined function curl_init() in C:wampwwwsocial-media-counttwitteroauthtwitteroauth.php on line 195

    • anakontaa

      sorry my mistake!! i had to go to WAMP Icon > PHP > PHP Extensions > check php_curl.

  • Parul Singh

    I tried the code on my local server but that gives me an error saying “Error opening output file”

  • kn

    i am using the google API key .. does it have any expiry time set?

  • This is quite useful thanks. Many people who understand how powerful social media can be in driving traffic to their websites use various social media tools such as Hootsuite to monitor their activity and make social media campaigns easier. However, being able to see the count on your own blog is helpful as well.

  • thrway11

    Seems like the instagram connection has some issues. Can’t seem to get the counter to update, maybe a change in their API?

  • illuminati176

    hello guys,
    Script is working perfectly (on localhost) except for
    instagram as thrway11 has mentioned. Can someone help me and explain to
    me you the script is not working on my server? it shows me Error opening
    output file instead of the followers count; Please help? what could me
    missing or disabled on the server that is generating this error?

  • Mufleeh Sadique

    Perfect script, but my bad I found it only after many hours of work almost doing all.

    The Vimeo count gives the number of users we follow, is there any quick way we can get the number of subscribers of our channel?

  • Jason Martinez

    This is great but I would like to make it so that a user on my site can authlogin and place their unique counter on their profile. any ideas?

  • Daan de Wilt

    When inserting username facebook in social_count.php the facebook counter is empty?

Be notified for new scripts