我正在尝试使用Snoocore库以编程方式向Reddit发布评论。
这是我的代码:
function postComment() {
var commentText = document.getElementById("response").value;
reddit('/api/comment').post({
api_type: 'json',
thing_id: getUrlVars()['link'],
text: commentText
});
}
我在我的按钮中用onclick事件调用它。
<input type="button" value="Save" id="save-button" data-role="button" onclick="postComment()">
函数postComment()执行,但我得到以下json响应:
>>> Reddit Response:
{
"json": {
"errors": [
[
"USER_REQUIRED",
"please sign in to do that",
null
]
]
}
}
>>> Endpoint URL: https://ssl.reddit.com/api/comment
>>> Endpoint method: POST
>>> Arguments: {
....
现在,我知道凭据是正确的。
我可以在代码的单独部分登录:
reddit.raw('http://www.reddit.com/api/me.json').get({
}).then(function(data) {
mainReddit(data);
});
但不发表评论。
为什么这不起作用?我登录了,为什么Reddit认为我不是?
编辑:
我添加了uh参数,现在我收到了403错误。
呃:data.data.modhash
我还将代码更改为:
function postComment() {
reddit.raw('http://www.reddit.com/api/me.json').get({
}).then(function(data) {
console.log(data);
var commentText = document.getElementById("response").value;
reddit('/api/comment').post({
api_type: 'json',
thing_id: getUrlVars()['link'],
text: commentText,
uh: data.data.modhash
});
});
}
答案 0 :(得分:1)
当您发布到Reddit时,您必须确保拥有完整的thing_id - 这意味着您必须包含t1_和t3_,具体取决于它的评论类型。