node.jsredditreddit-access-token

Cannot get reddit authentication token from /api/v1/access_token


I'm currently using the node.js reddit (https://www.npmjs.com/package/reddit) plugin which will automatically get and process the authentication token but for some reason, it's failing for me.

Error: Cannot obtain token for username -Arniox-. invalid_grant.

with the following code:

const opts = {
   username: process.env.REDDIT_USERNAME,
   password: process.env.REDDIT_PASSWORD,
   appId: process.env.REDDIT_APP_ID,
   appSecret: process.env.REDDIT_APP_SECRET
}

//Initialize Reddit client
var reddit = new RedditJS.Client(opts);

I tried hunting for the issue and ended up finding out that I cannot even login via the direct API url here: https://www.reddit.com/api/v1/access_token

I think maybe it might have something to do with my unique username (-Arniox-)? That's basically the only answer I have to this problem and I can't seem to get it to work.


Solution

  • I ended up finding the issue. The developer I account was using to log into for the bot was 2 Factor authenticated which breaks the API and won't allow you to log in.

    I had to create another account for a developer without 2-factor authentication.