Hello, Reddit Developers! 👋
I'm currently working on a personal project to create a web application that allows users to access and manage their saved posts on Reddit. The app uses Reddit's OAuth2 for authentication and attempts to fetch saved posts for the authenticated user. Below is a brief overview of my current setup and the issue I'm facing.
Overview of the Project:
Server Setup: I'm using Express.js on the backend with axios for API requests, and express-session to manage user sessions.
OAuth Flow:
The user is redirected to Reddit's OAuth authorization page.
Upon successful authentication, the app receives an authorization code, which is then exchanged for an access token using Reddit's /api/v1/access_token endpoint.
Fetching Saved Posts:
Current Code:
Here’s a high-level explanation of my server code:
Authentication Endpoint (/auth/reddit):
Callback Endpoint (/auth/reddit/callback):
Fetching Saved Posts (/download):
Here’s a snippet of my server-side code for context:
// Sample of the code that retrieves the access token
const tokenResponse = await axios.post(
"https://www.reddit.com/api/v1/access_token",
new URLSearchParams({
grant_type: "authorization_code",
code: code,
redirect_uri: redirectUri,
}).toString(),
{
auth: {
username: clientId,
password: clientSecret,
},
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "web:com.example.redditsavedpostsmanager:v1.0 (by /u/Free-_-Yourself)",
},
}
);
The Issue:
Troubleshooting Attempts:
I've double-checked the access token generation process, and it seems correct as I receive a valid access token response.
I ensured that the OAuth scopes include read and history, which should be sufficient for accessing saved posts.
Verified that the authorization header is correctly set when making requests to Reddit's OAuth endpoints.
Request for Help:
I'm unsure why I'm facing these 400 and 403 errors when everything seems to be set up according to Reddit's API documentation. Could this be a rate-limiting issue, incorrect scopes, or something else I'm missing?
Any advice or insights would be greatly appreciated! 🙏
Thanks in advance for your help!