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 “social-count.zip” 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 = [
    'wcd_facebook',
    'wcd_youtube',
    'wcd_twitter',
    'wcd_dribbble',
    'wcd_vimeo',
    'wcd_soundcloud',
    'wcd_gplus',
    'wcd_instagram'
];

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';  //https://www.facebook.com/google
$youtube_channel = 'Apple'; //http://www.youtube.com/user/apple
$dribbble_username = 'Facebook';  //http://dribbble.com/facebook
$vimeo_username = 'royalhandmadecustoms'; //https://vimeo.com/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


Twitter

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

create-new-app-twitter

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"; //https://twitter.com/amine_pv0
$oauth_access_token = ""; 
$oauth_access_token_secret = "";
$consumer_key = "";
$consumer_secret = "";

Instagram

Go to and create a new app

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

https://api.instagram.com/oauth/authorize?client_id=YOUR_CLIENT_ID&response_type=token&redirect_uri=YOUR_REDIRECT_URI

Then you will redirected to instagram app box, click on Authorize
By clicking on Authorize you will be redirected to
http://localhost/instagram/#access_token=[you-access-token]
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

google-plus-api-activate

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 :
https://plus.google.com/u/0/+InterestingEngineering/posts
from this url our Page ID is +InterestingEngineering
it can be like this
https://plus.google.com/u/0/104477202728652698005
so the page ID is 104477202728652698005

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

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

SoundCloud

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’ // https://www.facebook.com/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’; //https://www.facebook.com/VisuaspaceBacheca

        $youtube_channel = ”;

        $dribbble_username = ”;

        $vimeo_username = ”;

        • Gianluca Del Re

          and write in

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

          $expire = time()-$expire;

          $facebookUrl = ‘https://www.facebook.com/VisuaspaceBacheca/’.$fb_page;

          $cache_data = FetchData($cache);

          Where there problem that not view fans

          • leave the $facebookUrl like it is “$facebookUrl = ‘http://graph.facebook.com/’.$fb_page;”
            or “$facebookUrl = ‘http://graph.facebook.com/VisuaspaceBacheca’;”

  • Gianluca Del Re

    for second question i ask because i click on button only facebook for now and it don’t go to link https://www.facebook.com/VisuaspaceBacheca. 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 wwww.visuaspace.com

    • 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 http://www.visuaspace.com. <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

    hi,
    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?

Be notified for new scripts