I'm trying to add support for reddit flair api to reddit_api, but I don't seem to be getting anywhere.
I've added the following to urls.py
:
("api/", {
...
"flair": "flair/"
}),
And the following to reddit.py
:
@require_login
def set_flair(self, subreddit, user, text='', css_class=''):
"""Set flair of user in given subreddit"""
url = urls["flair"]
params = {'r': subreddit,
'user': user,
'text': text,
'css_class': css_class,
'uh': self.modhash}
return self._request_json(url, params)
But my code seems to have no discernable effect:
import reddit
r = reddit.Reddit(user_agent='User rating modifier')
r.login(user='xxxx', password='xxxx')
r.set_flair('subreddit', 'username', 'textflair', 'cssclass')
I don't get an error, but the user flair isn't added on reddit. The other features of reddit_api
work perfectly for me, and I have all the right moderator permissions on reddit. Have I gone wrong somewhere with my code?
Here is a working set_flair
function:
@require_login
def set_flair(self, subreddit, user, text='', css_class=''):
"""Set flair of user in given subreddit"""
url = urls["flair"]
params = {'r': subreddit,
'name': user,
'text': text,
'css_class': css_class,
'uh': self.user.modhash}
return self._request_json(url, params)
First error I've got after running your code was .error.USER_REQUIRED
("please login to do that"). API specifically states that user's modhash is required. So I've changed self.modhash
to self.user.modhash
.
The second error was .error.NO_USER.field-name
. And it was just a matter of changing user
parameter to name
.