oddluck / limnoria-plugins

Limnoria plugins I wrote or forked.
Do What The F*ck You Want To Public License
39 stars 18 forks source link

SpiffyTitles no longer pulling for reddit -- 403 #58

Open boringparty opened 8 months ago

boringparty commented 8 months ago

This is in the log. The URL is valid, however.

ERROR 2023-12-17T13:18:49 supybot SpiffyTitles: Reddit Error: 403 Client Error: Blocked for url: https://www.reddit.com/r/Pizza/comments/18keaxz.json
oddluck commented 8 months ago

Yeah, someone mentioned this to me yesterday... Knew this was coming eventually with the API changes... I need to look at the documentation, chances are an API key will now be required at minimum...

fred0r commented 6 months ago

@hello-party https://github.com/oddluck/limnoria-plugins/pull/62

Znuff commented 3 months ago

I've got this working locally, but I lack the skills to properly implement it.

You will need new Reddit "app" and set it to type SCRIPT, set the redirect URL to whatever, like http://localhost:8080 (it doesn't really matter)

Run the following code locally to fetch a Token (create a .py file, run it after):

#!/usr/bin/env python3
import requests
from requests.auth import HTTPBasicAuth

# Replace these with your client ID and secret from Reddit
client_id = 'CLIENT_ID'
client_secret = 'CLIENT_SECRET'

# Headers and data for the request
headers = {
    'User-Agent': 'Limnoria'
}
data = {
    'grant_type': 'client_credentials'
}

# Request to get the access token
response = requests.post('https://www.reddit.com/api/v1/access_token',
                         auth=HTTPBasicAuth(client_id, client_secret),
                         data=data, headers=headers)

# Extract the access token from the response
access_token = response.json().get('access_token')
print("Access Token:", access_token)

(please be aware that I lazied this with ChatGPT, but it works, replace the Client ID and Secret with the ones you got from creating the app on reddit.com)

Once you run the code, you will get the your new Access token.

In plugin.py, search for the handler_reddit function, look for headers and replace it with something like:

          headers = { "User-Agent": "Limnoria",
        "Authorization": "bearer YOUR_ACCESS_TOKEN" }

Replace the pattern URLs with oauth.reddit.com (instead of www.reddit.com).

Should be easy to implement by someone with more coding skills than me.

EDIT: Right... I completely didn't realize that the Reddit token has a TTL, which is 24 hours right now. Back to the drawing board.

fred0r commented 3 months ago

/me keeps his fingers crossed

klapvogn commented 2 weeks ago

I have made a PR to this issue. Hope it get merged :)