我正在尝试使用 API 获取 subreddit 中的所有链接,但它只返回一个 url。这是我的代码:
var request = require('request');
webpage = 'http://www.reddit.com/r/AmazonUnder5/top.json?limit=100';
//login
request.post('http://www.reddit.com/api/login',{form:{api_type:'json', passwd:'password', rem:true, user:'username'}});
//get urls
request({uri : webpage, json:true, headers:{useragent: 'mybot v. 0.0.1'}}, function(error, response, body) {
if(!error && response.statusCode == 200) {
for(var key in body.data.children) {
var url = body.data.children[key].data.url;
console.log(url);
}
}
});
Run Code Online (Sandbox Code Playgroud)
当我在浏览器中访问 json 链接时,它会返回所有 100 个帖子。
按照https://github.com/reddit/reddit/wiki/OAuth2 中描述的 OAuth2 登录流程,我到了 POST 到https://www.reddit.com/api/v1/access_token返回类似内容的地步这个:
{'token_type': 'bearer', 'expires_in': 3600, 'scope': 'identity', 'access_token': '*****'}
Run Code Online (Sandbox Code Playgroud)
然后我做
GET https://oauth.reddit.com/api/v1/me
Run Code Online (Sandbox Code Playgroud)
有了这个标题:
Authorization: bearer *****
Run Code Online (Sandbox Code Playgroud)
响应是 HTTP 403 Unauthorized。但为什么?很明显,访问令牌具有“身份”范围。还记录了 /api/v1/me 调用仅需要此范围。(见https://www.reddit.com/dev/api/oauth#GET_api_v1_me)
那么为什么我会收到 http 403 呢?
我正在尝试制作一个长时间运行的 Python 脚本,该脚本使用 PRAW 4.4.0 定期查询 Reddit 以获取新的提交/评论,首先我像这样初始化对象:
redditClient = praw.Reddit(
client_id=constants.REDDIT_CLIENT_ID,
client_secret=constants.REDDIT_CLIENT_SECRET,
user_agent=constants.REDDIT_USER_AGENT
)
Run Code Online (Sandbox Code Playgroud)
一段时间后,我收到以下错误:
请求错误('连接中止。',错误(104,'连接重置'))
我的猜测是发生这种情况是因为我保持连接打开,但我没有找到关闭它的方法。你能帮我弄清楚如何解决这个问题吗?
The new redesign of Reddit features a really slick WYSIWYG/Markdown editor. Screenshots:
Once clicking on "Switch to markdown":
Is this an open-source library available for implementation, or is this entirely an internal Reddit-only solution?
On another note, I've been comparing a whole bunch of Markdown editors, and can't seem to find anything that works really well with React. SimpleMDE isn't bad, but its last commit was two and a half years ago, and it has no official React bindings either. …
我想生成使用特定 subreddit 的用户的用户名列表。
据我所知,不可能简单地获得订阅 subreddit 的用户列表。如果这是不可能的,最好浏览所有线程并查看谁发表了评论。
我将如何处理这个问题?
subredditcmv=reddit.subreddit('changemyview')
cmv_subreddit=subredditcmv.top(limit=15)
cmv_dict={"Title":[], \
"Score":[], \
"id":[], \
"number_of_comments":[],\
"post":[],\
"created":[]
}
for posts in cmv_subreddit:
cmv_dict["Title"].append(posts.title)
cmv_dict["Score"].append(posts.score)
cmv_dict["id"].append(posts.id)
cmv_dict["number_of_comments"].append(posts.num_comments)
cmv_dict["post"].append(posts.selftext)
cmv_dict["created"].append(posts.created)
Run Code Online (Sandbox Code Playgroud)
收到此错误
文件“C:\Users\source\repos\lib\site-packages\prawcore\auth.py”,第 31 行,在 _post 引发 ResponseException(response)
ResponseException:收到 401 HTTP 响应
我所做的一切都不起作用,而且我不断收到可笑的 CORS 错误和其他问题。我只想做一个正常的宣誓,通过浏览器登录用户。我想使用 snowrap,但我什至无法使用它,因为我需要刷新令牌。
\n\n我已经授权该应用程序并从 API 获取“代码”,然后我应该通过向https://www.reddit.com/api/v1/access_token发出发布请求来使用该代码。
\n\n但我每次都会收到 CORS 错误。
\n\nCross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.reddit.com/api/v1/access_token. (Reason: missing token \xe2\x80\x98access-control-allow-headers\xe2\x80\x99 in CORS header \xe2\x80\x98Access-Control-Allow-Headers\xe2\x80\x99 from CORS preflight channel).\n\nCross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.reddit.com/api/v1/access_token. (Reason: CORS request did not succeed).\nRun Code Online (Sandbox Code Playgroud)\n\n代码:
\n\nconst redirect_uri = \'https://EXAMPLE.com/reddit/\';\nconst client_id = \'xxxxxxxxxxxxx\';\nconst queryString = window.location.search;\nconst urlParams = new URLSearchParams(queryString); /*global URLSearchParams*/\nconst code …Run Code Online (Sandbox Code Playgroud) 我想从reddit获取某个URL的分数.要添加"与reddit(count)共享"链接:
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);
}
});
}
Run Code Online (Sandbox Code Playgroud)
使用curl或浏览器调用url时,结果如Reddits API文档中所述.有一个子数组,其中包含一个带数字的分数.
的$.getJSON,然而,返回一个空的答案,萤火跨过它的时候看到.
这是reddit的保护方法吗?或者我使用getJSON错了?
我正在尝试在我的Mac上安装Reddit的Python库.我想使用PyCharm进行开发,因为我喜欢它作为Python IDE.
我在Virtual Box实例中运行Cassandra,Memcached,RabbitMQ和Postgres服务器,可通过Virtual Box Host-only适配器访问.这是有效的,因为我可以在虚拟盒中启动Reddit并从我的Mac访问它就好了.
运行paster脚本时,看看Reddit Python源安装是否在Mac上运行.我收到以下错误:
Traceback (most recent call last):
File "/Users/inflector/software/new-day/reddit/dev/bin/paster", line 8, in <module>
load_entry_point('PasteScript==1.7.5', 'console_scripts', 'paster')()
File "/Users/inflector/software/new-day/reddit/dev/lib/python2.7/site-packages/paste/script/command.py", line 93, in run
commands = get_commands()
File "/Users/inflector/software/new-day/reddit/dev/lib/python2.7/site-packages/paste/script/command.py", line 135, in get_commands
plugins = pluginlib.resolve_plugins(plugins)
File "/Users/inflector/software/new-day/reddit/dev/lib/python2.7/site-packages/paste/script/pluginlib.py", line 82, in resolve_plugins
pkg_resources.require(plugin)
File "build/bdist.linux-i686/egg/pkg_resources.py", line 666, in require
File "build/bdist.linux-i686/egg/pkg_resources.py", line 569, in resolve
pkg_resources.VersionConflict: (WebOb 1.2.3 (/Users/inflector/software/new-day/reddit/dev/lib/python2.7/site-packages), Requirement.parse('webob==1.0.8'))
Run Code Online (Sandbox Code Playgroud)
如果我将安装降级到WebOb 1.0.8,我会反过来,它想要'WebOb> = 1.2'.
'pip list'显示安装的这些包:
amqplib (1.0.2)
Babel (0.9.6)
bcrypt (1.0.2)
Beaker (1.6.4)
BeautifulSoup (3.2.1) …Run Code Online (Sandbox Code Playgroud) 所以我一直在尝试解析Reddits r/hot/.json API以获取主题信息的列表视图,但我似乎无法使我的JSON正确.我到处寻找,我似乎找不到如何为reddit做这个的好例子.这是我到目前为止...
JSONObject response = new JSONObject(result);
JSONObject data = response.getJSONObject("data");
JSONArray hotTopics = data.getJSONArray("children");
for(int i=0; i<hotTopics.length(); i++) {
JSONObject topic = hotTopics.getJSONObject(i);
String author = topic.getString("author");
String imageUrl = topic.getString("thumbnail");
String postTime = topic.getString("created_utc");
String rScore = topic.getString("score");
String title = topic.getString("title");
topicdata.add(new ListData(title, author, imageUrl, postTime, rScore));
Log.v(DEBUG_TAG,topicdata.toString());
}
Run Code Online (Sandbox Code Playgroud)
-------编辑可以提供更多详细信息我在" http://www.reddit.com/r/hot/.json?sort=new&count=25 " 上做了一个HttpGet请求当我运行我的代码时站起来我得到以下JSONException
07-06 22:23:11.628 2580-2580/com.google.android.gms.redditviewr.app W/System.err? org.json.JSONException: No value for author
07-06 22:23:11.632 2580-2580/com.google.android.gms.redditviewr.app W/System.err? at org.json.JSONObject.get(JSONObject.java:354)
07-06 22:23:11.632 2580-2580/com.google.android.gms.redditviewr.app W/System.err? at org.json.JSONObject.getString(JSONObject.java:514)
07-06 22:23:11.636 …