0

Try to make array with share counters for current URL of three social networks: Twitter, Facebook & VK. I need to get sum of all elements of this array and display result (into other function).

Array must be something like this [1, 2, 3].

This is my code:

$(document).ready(function() {

  var totalCount = new Array();

  // Twitter counter
  $.getJSON('http://cdn.api.twitter.com/1/urls/count.json?url=' + encodeURIComponent(location.href) + '&callback=?', function(response) {
    totalCount.push(response.count); // try to push response.count to array
  });

  // Facebook counter
  $.getJSON('http://graph.facebook.com/?id=' + encodeURIComponent(location.href), function(response) {
    totalCount.push(response.shares); // try to push response.shares to array
  });

  // VK counter
  $.getJSON('https://vk.com/share.php?act=count&index=1&url=' + encodeURIComponent(location.href) + '&callback=?', function(response) {});
  VK = {};
  VK.Share = {};
  VK.Share.count = function(index, count) { 
    totalCount.push(count); // try to push count to array
  };

  // Show array
  console.log(totalCount);

});

But this code is empty (show [] in Chrome console).

Any ideas? Help me please.

CBroe
  • 91,630
  • 14
  • 92
  • 150
Platon
  • 495
  • 1
  • 4
  • 11

0 Answers0