【发布时间】:2012-01-30 19:34:08
【问题描述】:
我正在尝试从 reddit 获取某个 URL 的分数。添加“与 reddit 分享(计数)”链接:
function redditCounter(url) {
// Get number of counts from reddit JSON api
// $.getJSON('http://www.reddit.com/api/info.json?url='+url+'',
$.getJSON('http://www.reddit.com/api/info.json?url=http://stackoverflow.com/q/811074/1288',
function(data) {
count = 0;
if (data.children.count() > 0) {
first_child = data.children[0];
alert(first_child.score);
}
});
}
当您使用 curl 或您的浏览器调用 url 时,结果与 Reddits API documentation 中描述的一样。有一个 children 数组,其中包含一个带有数字的分数。
然而,$.getJSON 返回一个空答案,在 firebug 中踩到它时会看到。
这可能是reddit的一种保护方法吗?还是我使用 getJSON 错误?
【问题讨论】: