Answer the question
In order to leave comments, you need to log in
How to like a reddit post using python?
There is a task to write a reddit bot in python that would like posts at a certain interval. I'm using the official API from Reddit. However, I could not find information on how to put a like through it. While there is such a code (Habr inserted tabs a little incorrectly):
CLIENT_ID = profile['CLIENT_ID']
SECRET_ID = profile['SECRET_ID']
USERNAME = profile['USERNAME']
PASSWORD = profile['PASSWORD']
# Данные для авторизации
auth = requests.auth.HTTPBasicAuth(CLIENT_ID, SECRET_ID)
data = {
'grant_type' : 'password',
'username' : USERNAME,
'password' : PASSWORD
}
headers = {
'User-Agent': 'MyApi/0.0.1'
}
response = requests.post('https://reddit.com/api/v1/access_token', auth=auth, data=data, headers=headers)
TOKEN = response.json()['access_token']
headers = {**headers, **{'Authorization': f'bearer {TOKEN}'}}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question