我正在尝试从 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 文档中所述。有一个 children 数组,其中包含一个带有数字的分数。
然而$.getJSON
,返回一个空答案,当在萤火虫中跨过它时可以看到。
这可能是reddit的一种保护方法吗?还是我使用 getJSON 错误?