d
Amit DhamuSoftware Engineer
 

Social Media Share Counts

1 minute read 00000 views
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)
  }
)

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