Social Follower Count using PHP

This post will help you to find snippets to get followers count for social platforms like Facebook, Twitter, Google plus,  Youtube, Instagram, Pinterest  and Tumblr.

Facebook Followers Count
$FBFollowercount = file_get_contents('http://api.facebook.com/method/fql.query?format=json&query=select+fan_count+from+page+where+page_id%3D355692061120689');
$data = json_decode($FBFollow);
echo $data[0]->fan_count;

Twitter followers Count
require_once 'twitteroauth.php';
define("CONSUMER_KEY", "****consumer key*******");
define("CONSUMER_SECRET", "*******Consumer secret********");
define("OAUTH_TOKEN", "**********Oauth token*******");
define("OAUTH_SECRET", "*****Oauth Secret********");
$username = 'Walkswithmenet'; //Your twitter screen name or page name
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
$followers = $connection->get('https://api.twitter.com/1.1/users/show.json?screen_name='.$username);
echo ($followers->followers_count);

Google Plus Followers Count
/ get api https://code.google.com/apis/console?hl=en#access
$google_api_key = 'YOUR_API';
$page_id = 'YOUR_PAGE_ID';
$data = @file_get_contents("https://www.googleapis.com/plus/v1/people/$page_id?key=$google_api_key");
$data = json_decode($data, true);
echo $data['plusOneCount'];

Youtube Subscribers
$channel_name = 'Your Channel';
$data = file_get_contents("http://gdata.youtube.com/feeds/api/users/$channel_name?alt=json");
$data = json_decode($data, true);
$subscribersDetails = $data['entry']['yt$statistics'];
echo $subscribersDetails['subscriberCount'].'<br />';
echo $subscribersDetails['viewCount'].'<br />';

Instagram Followers
Register the app you will get an API Key and secret.
$api_key = 'API_KEY';
$user_id = 'UID';
$data = @file_get_contents("https://api.instagram.com/v1/users/$user_id/?client_id=$api_key");
$data = json_decode($data, true);
echo '<pre/>';
print_r($data);
echo $data['data']['counts']['followed_by'];

Pinterest Followers Count
$metas = get_meta_tags('http://pinterest.com/YOUR PINTREST ACCOUNT NAME/');
print_r($metas['pinterestapp:followers']);

Tumblr Likes
Login to Tumblr -> Setting Menu -> APP ->Register your APP get the API Key and secret key.
$api_key = 'API_KEY';
$blog_name = 'Blog_name';
$data = @file_get_contents("http://api.tumblr.com/v2/blog/$blog_name/info?api_key=$api_key");
$data = json_decode($data, true);
echo '<pre/>';
print_r($data);
echo $data['response']['blog']['likes'];


10 comments :

Custom Social Share Buttons



Now a days social media is important part of web development and brand promotions. Social share buttons are widely used things on a web site, while developing each site we concentrate how we can use all buttons,icons images are very close to the template.

This article will help to create custom social share buttons for Facebook, Google Plus, Pinterest, Tumblr , Twitter and Linked In.

For Facebook share button.
<a id="ref_fb"  href="http://www.facebook.com/sharer.php?s=100&amp;p[title]=<?php echo $title;?>&amp;p[summary]=<?php echo $description;?>&amp;p[url]=<?php echo urlencode($share_url);?>&amp;
p[images][0]=<?php echo $image_url;?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600'); return false;"><img src="your custom facebook share button image" alt=""/></a>

Twitter Share Button
<a id="ref_tw" href="http://twitter.com/home?status=<?php echo $title; ?>+<?php echo urlencode($share_url);?>"  onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false;"><img src="your custom twitter share button image" alt=""/></a>

Google Plus share button
<a id="ref_gp" href="https://plus.google.com/share?url=<?php echo urlencode($share_url);?>"
onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false"><img src="your custom gplus share button image" alt=""/></a>

Pinterest share button.
<a id="ref_pr" href="http://pinterest.com/pin/create/bookmarklet/?media=<?php echo urlencode($share_image);?>&amp;
url=<?php echo urlencode($share_url);?>&amp;
is_video=false&amp;description=<?php echo $description;?>"
onclick="javascript:window.open(this.href, '_blank', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false;"><img src="your custom pin share button image" alt=""/></a>

Linked In share button.
<a id="ref_lkd" href="http://www.linkedin.com/shareArticle?mini=true&url=<?php echo urlencode($share_url);?>&title=<?php echo strip_tags($title); ?>&source=<?php echo urlencode($siteurl);?>"
onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false;"><img src="your custom pin share button image" alt=""/></a>

Tumblr share button.
<a id="ref_tum" href="http://www.tumblr.com/share/photo?source=<?php echo urlencode($share_image);?>&amp;caption=<?php echo $description;?>&amp;clickthru=<?php echo urlencode($share_url);?>"
onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false;"><img src="your custom pin share button image" alt=""/></a>

Dynamically reate Social share buttons
var share_url         =    "your url to share" ;
var share_image      =    "your image to share";
//full url not ../images should be http://www.
var title               =    "title";
var description       =    "description";
//title and description should be formatted ie, remove all special char otherwise it may creates errors on social media sites.
var FB_url             =    "http://www.facebook.com/sharer.php?s=100&p[title]="+(title)+"&p[summary]="+description+"&p[url]="+encodeURIComponent(share_url)+"&p[images][0]="+(share_image);
var GP_url            =    "https://plus.google.com/share?url="+encodeURIComponent(share_url);
var TW_url            =    "http://twitter.com/home?status="+escape(title)+"+"+encodeURIComponent(share_url);
var Pt_url            =    "http://pinterest.com/pin/create/bookmarklet/?media="+encodeURIComponent(share_image)+"&url="+encodeURIComponent(share_url)+"& is_video=false&description="+description;
var TB_url            =    "http://www.tumblr.com/share/photo?source="+encodeURIComponent(share_image)+"&caption="+(description)+"&clickthru="+encodeURIComponent(share_url);
var LK_url            =    "http://www.linkedin.com/shareArticle?mini=true&url="+encodeURIComponent(share_url)+"&title="+(title)+"&source="+encodeURIComponent(siteurl);
jQuery("#ref_fb").attr('href',FB_url);
jQuery("#ref_gp").attr('href',GP_url);
jQuery("#ref_tw").attr('href',TW_url);
jQuery("#ref_pr").attr('href',Pt_url);
jQuery("#ref_tum").attr('href',TB_url);
jQuery("#ref_lkd").attr('href',LK_url);

Note: please make sure to add jquery library in page.

0 comments :