Amit Dhamu

Writes Code

Social Media Share Counts

var url = "http://www.google.com";

// Twitter
$.getJSON("https://cdn.api.twitter.com/1/urls/count.json?url=" + url + "&callback=?", function(result) {
    console.log(result.count);
});

// Facebook
$.getJSON("https://graph.facebook.com/" + url, function(result) {
   console.log(result.shares);
});

// Pinterest
$.getJSON("https://api.pinterest.com/v1/urls/count.json?callback=&url=" + url, function(result) {
   console.log(result.count);
});

// StumbleUpon
$.getJSON("https://www.stumbleupon.com/services/1.01/badge.getinfo?url=" + url, function(result) {
   console.log(result.result.views);
});

// Google Plus
var request = [{
    "method":"pos.plusones.get",
    "id":"p",
    "params":{
        "nolog":true,
        "id":url,
        "source":"widget",
        "userId":"@viewer",
        "groupId":"@self"
        },
    "jsonrpc":"2.0",
    "key":"p",
    "apiVersion":"v1"
}];

$.ajax({
    url: "https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ",
    type: "POST",
    data: JSON.stringify(request),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(response) {
        console.log(response[0].result.metadata.globalCounts.count);
    }
});


You can find more information and details about the result objects on this helpful Github Gist.


social media / share count

← Solr - Delete By Query Search Git Commit History →