Reading list Switch to dark mode

    Popular Social Media Share Count on your website

    Updated 17 January 2013

    Simplest way to put the share count of your website url. There having various social media website where you want share your website page.

    Here is the the Demo code of getting share count of your share page.

    $uri = & JFactory::getURI();
    $pageURL = $uri->toString();
    $encodedPageUrl=urlencode($pageURL);
    
    # URL for Stumbleupon 
    $stumbleuponURL = str_replace('http://','',$pageURL);
    $shortPageUrlStumble=urlencode($stumbleuponURL);
    $stmbleURL = urlencode($shortPageUrlStumble);
    
    #Get Number of Tweets from Twitter
    function get_tweets($url) {    
      $json_string = file_get_contents('http://urls.api.twitter.com/1/urls/count.json?url=' . $url);
      $json = json_decode($json_string, true);
      return intval( $json['count'] );
    }
    $count_tweet =  get_tweets($encodedPageUrl);
    
    #Get Number of Facebook Shares
    function get_likes($url) {
      $json_string = file_get_contents('http://api.facebook.com/restserver.php?method=links.getStats&format=json&urls=' . $url);
      $json = json_decode($json_string, true);  
      return intval( $json['0']['share_count'] );
    }
    $count_facebook =  get_likes($encodedPageUrl);
    
    #Get Number of LinkedIn Shares
    function get_shares($url) {    
      $json_string = file_get_contents("http://www.linkedin.com/countserv/count/share?url=$url&format=json");
      $json = json_decode($json_string, true);
      return intval( $json['count'] );
    }
    $count_LinkedIn =  get_shares($encodedPageUrl);
    
    #Get Number of Google+1′s
    function get_plusones($url) {
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, "https://clients6.google.com/rpc");
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
      $curl_results = curl_exec ($curl);
      curl_close ($curl);
      $json = json_decode($curl_results, true);
      return intval( $json[0]['result']['metadata']['globalCounts']['count'] );
    }
    $count_Google =  get_plusones($pageURL);
    
    #Get Number of Stumbleupon Shares
    function get_stumbleupon($url) {    
      $json_string = file_get_contents("http://www.stumbleupon.com/services/1.01/badge.getinfo?url=$url&format=json");
      $json = json_decode($json_string, true); 
      return intval( $json['result']['views'] );
    }
    $count_Stumbleupon =  get_stumbleupon($stmbleURL);
    
    #Get Number of Reddit Shares
    function get_reddit($url) {    
      $json_string = file_get_contents('http://buttons.reddit.com/button_info.json?url='.$url);
      $json = json_decode($json_string, true);
      return intval( $json['data']['children']['0']['data']['ups'] );
    }
    $count_Reddit =  get_reddit($encodedPageUrl);
    
    #Get Number of Delicious Shares
    function get_delicious($url) {    
      $json_string = file_get_contents('http://feeds.delicious.com/v2/json/urlinfo/data?url='.$url);
      $json = json_decode($json_string, true);
      return intval( $json['0']['total_posts']);
    }
    $count_Delicious =  get_delicious($encodedPageUrl);
    
    #Get Number of Pinterest Shares
    $get_pinterest = json_decode(preg_replace('/^receiveCount\((.*)\)$/', "\\1",file_get_contents('http://api.pinterest.com/v1/urls/count.json?callback=receiveCount&url='.$shortPageUrl)));
    $count_Pinterest = $get_pinterest->count;
    if($count_Pinterest=='-')
    {
    	$count_Pinterest=0;
    }

     

    Start your headless eCommerce
    now.
    Find out More
    . . .

    Leave a Comment

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


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home