【发布时间】:2021-07-24 22:06:52
【问题描述】:
所以,我编写了以下代码,使用 Reddit API 在 Reddit 上发布图片。
const request = require('request')
let access_token = "redacted"
let url = 'https://oauth.reddit.com/api/submit'
let headers = {
'Content-type': 'application/x-www-form-urlencoded',
"Authorization": "bearer " + access_token,
"User-Agent": "manage your reddit easily in the maxi time created in some idea of mine by u/_jaypatel"
}
let data = {
'sr':'testingground4bots',
'api_type': "json",
'title': 'Testing post creation',
'spoiler': false,
'nsfw' : false,
'resubmit': false,
'sendreplies': false,
'text':"This is raw api test",
'kind':'image',
'url':'https://i.imgur.com/fLZ35cI.jpg',
"extension": "json"
}
var options = {
url, headers, data
}
request.post(options,function (error, response, body) {
if (error) {
console.log(error);
}
else{
console.log(body);
}
}
);
我一次又一次地遇到这个错误。
{"jquery": [[0, 1, "call", ["body"]], [1, 2, "attr", "find"], [2, 3, "call", [".status"]], [3, 4, "attr", "hide"], [4, 5, "call", []], [5, 6, "attr", "html"], [6, 7, "call", [""]], [7, 8, "attr", "end"], [8, 9, "call", []], [1, 10, "attr", "find"], [10, 11, "call", [".error.BAD_SR_NAME.field-sr"]], [11, 12, "attr", "show"], [12, 13, "call", []], [13, 14, "attr", "text"], [14, 15, "call", ["This community name isn't recognizable. Check the spelling and try again."]], [15, 16, "attr", "end"], [16, 17, "call", []]], "success": false}
我首先编写了一个 Python 脚本,如下所示,它有效,我想用 Node JS 编写一个,但我做不到。这是python代码
import requests
access_token = "redacted"
headers = {
"Authorization": "bearer " + access_token,
"User-Agent": "manage your reddit easily in the maxi time created in some idea of mine by u/_jaypatel"
}
data = {
'sr':'testingground4bots',
'api_type': "json",
'title': 'Testing post creation',
'spoiler': False,
'nsfw' : False,
'resubmit': False,
'sendreplies': False,
'text':"This is raw api test",
'kind':'image',
'url':'https://i.imgur.com/fLZ35cI.jpg',
"extension": "json",
"uh":"74641dhxxdd1d8da2f8d06d267dec57369ffcb6098cc7cd2f1"
}
r = requests.post("https://oauth.reddit.com/api/submit", headers=headers, data=data)
content = r.json()
print(content)
如何修复我的 Node JS 脚本以使其正常工作?任何帮助将不胜感激。
【问题讨论】:
-
显而易见的问题:您的 Python 脚本有一个
uh值,而您的 Node 脚本没有...为什么? -
uh不是强制性的,即使我包含uh,它也会给我同样的错误