0

我尝试在我的网站上从 StumbleUpon 获取 URL 的共享(查看)计数(我在官方 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
}

有任何想法吗?如果可以的话,请帮助我!

4

0 回答 0