使用PRAW

时间:2019-05-29 15:33:15

标签: python reddit

我运行了代码,它给了我很多错误,例如“ invalid_grant错误处理请求”。在我的实际代码中,我的ID和密码设置正确。我在做什么错了?

import random
import praw

jokes = open('jokelist.txt').read().splitlines()
joke = ''

#Sets up base of bot
reddit = praw.Reddit(client_id='',
                             client_secret = '',
                             username = 'JokeMeBot',
                             password = '',
                             user_agent = 'JokeMeBot by /u/Tawkins')


#sets the subreddit
subreddit = reddit.subreddit('dadjokes')

#how to call the bot
keyword = '!JokeMe'
#Checks if the keyword is in the subreddit
for comment in subreddit.stream.comments():
    if keyword in comment.body:
#sets to a random joke and posts
        joke = random.choice(jokes)
        comment.reply(joke)
        print('posted')
    else:
        print("oops")

1 个答案:

答案 0 :(得分:0)

从praw文档中:

https://praw.readthedocs.io/en/latest/getting_started/authentication.html#script-application

  

注意

     

如果引发以下异常,请仔细检查您的凭据,   并确保您使用的用户名和密码用于   与应用程序关联的同一用户:

     

OAuthException:invalid_grant错误处理请求

因此,我会仔细检查您的凭据,看看是否可以解决。 请记住,用户名是您的reddit帐户名称,而不是漫游器的名称。

相关问题