Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpiffyTitles no longer pulling for reddit -- 403 #58

Open
boringparty opened this issue Dec 17, 2023 · 5 comments
Open

SpiffyTitles no longer pulling for reddit -- 403 #58

boringparty opened this issue Dec 17, 2023 · 5 comments

Comments

@boringparty
Copy link
Contributor

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
Copy link
Owner

oddluck commented Dec 17, 2023

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
Copy link
Contributor

fred0r commented Mar 2, 2024

@hello-party
#62

@Znuff
Copy link
Contributor

Znuff commented May 13, 2024

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
Copy link
Contributor

fred0r commented May 14, 2024

/me keeps his fingers crossed

@klapvogn
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants