我正在尝试使用C#和Json.Net为Windows Phone 7创建一个reddit应用程序(仅用于练习).我试图把json转换成c#可以使用的东西,以及其他一些东西.我可以提取我想要的数据,但不知道我是否正在使用正确的方法.然后,一旦我有了json数据,我就无法将其转换为自定义对象.无论如何,我确信这段代码中有很多错误,所以任何帮助理顺我的标题都会非常感激.
这是代码:
public partial class MainPage : PhoneApplicationPage
{
string json = "";
RootObject topic = new RootObject();
public MainPage()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
textBlock1.Text = "Retrieving...";
string url = @"http://www.reddit.com/r/all.json";
HttpWebRequest hWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
hWebRequest.Method = "GET";
hWebRequest.BeginGetResponse(Response_Completed, hWebRequest);
}
public void Response_Completed(IAsyncResult result)
{
HttpWebRequest request = (HttpWebRequest)result.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
{
json = streamReader.ReadToEnd();
topic = JsonConvert.DeserializeObject<RootObject>(json);
}
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
//textBlock2.Text …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Devise 和omniauth-reddit gem 来通过Reddit 实现oAuth。
\n\n它似乎可以很好地传递本地 url 和 api 密钥。
\n\nhttps://ssl.reddit.com/api/v1/authorize?response_type=account&client_id=API_KEY&redirect_uri=http%3A%2F%2F127.0.0.1%3A3000%2Fusers%2Fauth%2Freddit%2Fcallback&scope=identity\nRun Code Online (Sandbox Code Playgroud)\n\n然而我得到的回应是:
\n\nforbidden (reddit.com)\n\nyou are not allowed to do that\n\xe2\x80\x94 invalid redirect_uri parameter.\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试将redirect_uri设置为127.0.0.1:3000以及托管url(heroku),但无济于事。
\n\n所以现在我不明白我是否仍然只是给他们提供了错误的 URL 或者传递了不应该存在的参数。
\n\n谢谢你的帮助!
\n我只是想知道是否有一种简单的方法来迭代特定用户的所有评论(我想检查一个特定的短语).任何帮助表示赞赏:)
我想要一个在后台运行的脚本,该脚本将每小时左右获取 subreddit 数据。现在,由于我不想在数据库中出现重复的条目,所以我想根据created_utc过滤搜索结果
这就是我目前所拥有的:
r = praw.Reddit(user_agent='soc')
submissions = r.get_subreddit('soccer').get_hot()
Run Code Online (Sandbox Code Playgroud)
这就是我想要的:
r = praw.Reddit(user_agent='soc')
submissions = r.get_subreddit('soccer').get_hot(created_utc > '2016-02-18 14:33:14.000')
Run Code Online (Sandbox Code Playgroud)
有哪些方法可以实现这一目标?
我一直在使用它作为资源:https : //github.com/reddit/reddit/wiki/OAuth2-Quick-Start-Example
我正在参考 Curl 示例来获取令牌。
这正是我在终端中运行的内容:
curl -X POST -d 'grant_type=password&username=ollynov14@password=myrealpassword' --user 'jRje7BA55aycvA:myrealsecret' https://www.reddit.com/api/v1/access_token
(当然,我在上面的那些字段中有我的实际秘密和密码)
并且我收到以下错误:(
{"message": "Too Many Requests", "error": 429}
我从一开始就收到此错误,因此我认为这实际上与我运行此 curl 的次数无关)
我刚刚在几个小时前注册了 Reddit,以防万一……
有谁知道为什么我可能无法从 Reddit API 获取访问令牌?非常感激。
如果用户名不是某个用户,我正在制作一个带有不发布选项的机器人。
Reddit 用户名在这两种情况下都可以包含字母和数字。
哪个正则表达式可用于识别这样的用户名?格式是/u/USERNAME用户名可以包含大小写和数字的字母,例如ExaMp13.
我试过了 /u/[A-Z][a-z][0-9]
我想在reddit上收集一些帖子标题来做分析。通过不断调试我的代码,我可以得到一些帖子的标题。突然我在尝试使用 PRAW 收集帖子时收到了 Forbidden 403。网上的解释是:“绝对禁止访问您试图访问的页面或资源。换句话说,403 错误意味着您无权访问您试图查看的任何内容”。请告诉我我该怎么做。谢谢
尝试添加一些标题并使用时间延迟
url="https://www.reddit.com"
my_headers=["Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html",
"Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31"
]
def get_content(url,headers):
randdom_header=random.choice(headers)
req=urllib.Request(url)
req.add_header("User-Agent",randdom_header)
req.add_header("Host","www.reddit.com")
req.add_header("Referer","https://www.reddit.com")
req.add_header("GET",url)
content=urllib.urlopen(req).read()
return content
print (get_content(url,my_headers))
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用PRAW从 Reddit subreddits 检索消息。它在大多数情况下都能正常工作,但我收到以下错误消息:消息太长。我正在使用pytelegrambotApi
片段:
import praw
import telebot
bot = telebot.TeleBot(token)
reddit = praw.Reddit(
client_id=client, #these details are given accordingly and are correct. No errors here.
client_secret=secret,
user_agent="user_agent",
)
def get_posts(sub):
for submission in reddit.subreddit(sub).hot(limit=10):
print(submission)
if submission.author.is_mod:
continue
elif submission.selftext=="":
return submission.title,submission.url
else:
print("It's working")
print(submission.url)
return submission.title,submission.selftext
@bot.message_handler(func=lambda message: True)
def echo_message(message):
subreddit = message.text
title,post = get_posts(subreddit)
m = title + "\n" + post
bot.reply_to(message,m)
bot.infinity_polling()
Run Code Online (Sandbox Code Playgroud)
我需要一直抓住subreddit中的热门评论.
我已经尝试抓住所有提交内容并迭代它们,但不幸的是,您可以获得的帖子数量限制为1000.
我尝试过使用Subreddit.get_comments,但它只返回25条评论.
所以我正在寻找解决方法.
你能帮我吗?
我构建了一个Chrome扩展脚本,该脚本应该在Reddit上运行。
我的剧本:
console.log("hello world");
Run Code Online (Sandbox Code Playgroud)
我的manifest.json
{
"manifest_version": 2,
"name": "Name",
"description": "Desc",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png"
},
"content_scripts": [
{
"matches": [
"*://reddit.com/*"
],
"js": [
"contentscript.js"
],
"run_at": "document_end"
}
],
"permissions": [
"tabs", "*://reddit.com/*", "activeTab"
]
}
Run Code Online (Sandbox Code Playgroud)
该脚本未显示在chrome dev工具的“内容脚本”部分中。有谁知道为什么我的扩展程序没有运行?
reddit ×10
praw ×5
python ×5
oauth-2.0 ×2
api ×1
c# ×1
curl ×1
devise ×1
javascript ×1
json ×1
oauth ×1
python-3.x ×1
regex ×1
telegram-bot ×1