Get social media activity count of url using php

Hello Friends,

We all know that we widely used social media for the marketing of our different thinks over the world. So we get the information about what status of our thinks. The status means information in the form people like’s, share, comment’s etc.

For that I post this blog to get complete information of the URL from following social media.

  1. Facebook.
  2. Twitter.
  3. Linkedin.
  4. Google Plus (G-Plus).

There are following ways to get information from site.

Method-1: Code for getting like’s of particular URL from face-book, twitter and Google plus.  


<?php

$url = 'http://www.indieswebs.com/';

$json = file_get_contents("http://api.sharedcount.com/?url=" . rawurlencode($url));

$counts = json_decode($json, true);

echo "This page has " . $counts["Twitter"] ." tweets, " . $counts["Facebook"]["like_count"] . " likes, and ". $counts["GooglePlusOne"] . "+1's";

?>

Method-2: Code for getting activities of particular URL from face-book, twitter, Google plus and LinkedIn. 


<?php

//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'] );

}

//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'] );

}

//Get Number of Facebook Shares/Like/Comment/Click

function get_likes($url)

{

$json_string = file_get_contents('http://graph.facebook.com/?ids=' . $url);

$json = json_decode($json_string, true);

return intval( $json[$url]['shares'] );

}

//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'] );

}

$facecount = get_likes('http://www.indieswebs.com/');

echo "<br />The Answer For Facebook".$facecount;

$linkdinshare = get_shares('http://www.indieswebs.com/');

echo "<br />The Answer For LINKDIN".$linkdinshare;

$tweetcount = get_tweets('http://www.indieswebs.com/');

echo "<br />The Answer For Tweet".$tweetcount;

$gpcount = get_plusones('http://www.indieswebs.com/');

echo "<br />The Answer For Google".$gpcount;

?>

I Hope this will help you

Thank you

Advertisements

Speak Your Mind

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: