Having a strong online social presence is a great way of engaging and interacting with your visitors, and potential customers / clients.

Getting your Social Share Counts in PHP

But how do you actually track how engaged your content is and how many times it has been shared?

Thankfully, for any web developer, designer or webmaster, there is a great selection or tools available that'll quickly pull in your social counts such as AddThis or ShareThis. But what if you don't want an overly bloated solution to a somewhat trivial task? Why do you need the overhead and slow speeds of AddThis when you can easily achieve the same result yourself.

Here at ALJT Media, we've put together our own method that easily lets you send a request to an endpoint that in turn calculates the social counts from the platforms and returns the response to you. We setup a scheduler that automatically identifies hot content and will re-poll the endpoint. We then cache the results from each of the API's and return the response.

So, what are the social endpoints?

Twitter Share Count


This will produce the following response:

    "count": 22,
    "url": "http://www.madebymagnitude.com/"

Facebook Share Count


This will produce the following response:

   "id": "http://www.madebymagnitude.com",
   "shares": 60

The Facebook Graph endpoint will accept a list of multiple URL's using the 'ids' parameter:


This will produce the following response:

   "http://www.madebymagnitude.com": {
      "id": "http://www.madebymagnitude.com",
      "shares": 60
   "http://www.madebymagnitude.com/stalkr/": {
      "id": "http://www.madebymagnitude.com/stalkr/",
      "shares": 204

Facebook Page Likes


We have reduced the response down for demonstrative purposes, but just go to the URL above to see a complete list of fields returned (there's about 20).

   "username": "ALJTMedia",
   "website": "http://www.madebymagnitude.com/",   
   "likes": 551

Facebook Comments, Likes and Share Counts


This will produce the following response:

    "url": "http://www.madebymagnitude.com",
    "normalized_url": "http://www.madebymagnitude.com/",
    "share_count": 11,
    "like_count": 23,
    "comment_count": 26,
    "total_count": 60,
    "click_count": 0,
    "comments_fbid": 10150451628634400,
    "commentsbox_count": 0

Google Plus +1 Count

Google is slightly different to the other social networks and requires you to send a POST request to their endpoint with the following data:

    "method": "pos.plusones.get",
    "id": "p",
    "params": {
        "nolog": true,
        "id": "http://www.madebymagnitude.com",
        "source": "widget",
        "userId": "@viewer",
        "groupId": "@self"
    "jsonrpc": "2.0",
    "key": "YOUR_API_KEY",
    "apiVersion": "v1"

This will return the following response:

    "result": { 
        "kind": "pos#plusones", 
        "id": "http://www.madebymagnitude.com", 
        "isSetByViewer": false, 
        "metadata": {
            "type": "URL", 
            "globalCounts": {
                "count": 897.0
    } ,
    "id": "YOUR_API_KEY"

Buffer Share Count


This will produce the following response:

    "shares": 0

Pinterest Share Count


This will produce the following response:

    "count": 7,
    "url": "http://www.madebymagnitude.com/blog/"

LinkedIn Share Count


This will produce the following response:

    "count": 6,
    "fCnt": "6",
    "fCntPlusOne": "7",
    "url": "http://www.madebymagnitude.com"

StumbleUpon Share Count


This will produce the following response:

    "result": {
        "url": "http://www.madebymagnitude.com/",
        "in_index": true,
        "publicid": "2jipmF",
        "views": "522",
        "title": "Web Design Cheshire, Chester - ALJT Media",
        "thumbnail": "http://cdn.stumble-upon.com/mthumb/380/162799380.jpg",
        "thumbnail_b": "http://cdn.stumble-upon.com/bthumb/380/162799380.jpg",
        "submit_link": "http://www.stumbleupon.com/submit/?url=http://www.madebymagnitude.com/",
        "badge_link": "http://www.stumbleupon.com/badge/?url=http://www.madebymagnitude.com/",
        "info_link": "http://www.stumbleupon.com/url/www.madebymagnitude.com/"
    "timestamp": 1392302605,
    "success": true

Reddit Share Count


This will produce the following response:

    "kind": "Listing",
    "data": {
        "modhash": "f0sj316zyt7c9aed53384663b16c7479099f1e991b5179adc5",
        "children": [{
            "kind": "t3",
            "data": {                
                "score": 3,                
                "downs": 1,                
                "ups": 4
        "after": null,
        "before": null

Gimme Some PHP - How Is It Done?

PHP's cURL extension makes fetching this data extremely easy and can be achieved in a matter of a few lines of code.

For the majority, you need to send a simple GET request:

# Setup cURL
$curl = curl_init();
# URL to call
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
# Get the response
$response = curl_exec($curl);
# Close connection
# Return JSON
return json_decode($response, true);

For Google+, you'll want to send a POST request:

curl_setopt($curl, CURLOPT_POST, 1);

Social Cloud Counts

We've moved this service to a simple cloud platform that we're opening for you all to use. You just send the URL you want and we'll return a complete response for you. The information is cached on a per-URL basis for 30 minutes.

Social Endpoint

The current endpoint is:


You only need to pass across the URL parameter, an example is:


This will produce the following

    "twitter": 19407871,
    "facebook": {
        "share_count": 0,
        "like_count": 0,
        "comment_count": 0,
        "total_count": 0,
        "click_count": 0
    "buffer": 3210,
    "pinterest": 710372,
    "linkedin": 63776,
    "stumbleupon": 254954,
    "reddit": {
        "score": 151,
        "ups": 222,
        "downs": 85
    "google": 0

We'll be updating the social shared counter API platform going forward as part of our new cloud services. So if you start using the endpoint, you'll notice improvements including enhancements to select the social networks you want to gather data from.

Make your Instagram beautiful. Preview your images before you post them ›