如何从StumbleUpon获取当前页面URL的共享(查看)计数(使用jQuery.getJSON)?

时间:2015-09-24 08:32:14

标签: jquery json stumbleupon

我尝试在我的网站上获取来自StumbleUpon的URL的共享(查看)计数(我在official API中使用此页面来理解JSON响应):

$.getJSON('http://www.stumbleupon.com/services/1.01/badge.getinfo?url=' + encodeURIComponent(location.href) + '&callback=?', function(response) {
  console.log(response.result.views);
});

我也试试这段代码:

$.getJSON('http://www.stumbleupon.com/services/1.01/badge.getinfo?url=' + encodeURIComponent(location.href) + '&callback=?', function(response) {
  var getResult = 'result';
  for (var getResult in response) {
    if (response.hasOwnProperty(getResult)) {
      var count = response.getResult.views;
      break;
    }
  }
  console.log(count);
});

Google Chrome控制台总是向我显示此错误消息:

badge.getinfo?url=http%3A%2F%2Fmysite.com%2F&callback=jQuery11120638845409732312_14430823…:1 
Uncaught SyntaxError: Unexpected token :

如果我在浏览器中尝试此链接http://www.stumbleupon.com/services/1.01/badge.getinfo?url=http://www.treehugger.com(例如),我会收到此回复:

{
    "result": {
        "url": "http:\/\/www.treehugger.com\/",
        "in_index": true,
        "publicid": "1tin26",
        "views": 109703,
        "title": "TreeHugger",
        "thumbnail": "http:\/\/cdn.stumble-upon.com\/mthumb\/428\/925428.jpg",
        "thumbnail_b": "http:\/\/cdn.stumble-upon.com\/bthumb\/428\/925428.jpg",
        "submit_link": "http:\/\/www.www.stumbleupon.com\/submit?url=http:\/\/www.treehugger.com\/",
        "badge_link": "http:\/\/www.www.stumbleupon.com\/badge?url=http:\/\/www.treehugger.com\/",
        "info_link": "http:\/\/www.www.stumbleupon.com\/url\/www.treehugger.com\/"
    },
    "timestamp": 1289496144,
    "success": true
}

有什么想法吗?如果可以,请帮助我!

0 个答案:

没有答案