Reddit Integration

Hey all,

I am working on scenario where I have to use reddit node and a custom node.

For the custom node I need the Token:
image

Do you know the url we have to use in field “redirect uri”?
Also do we have to do the registration process they mention at the top right of the image?

Thanks

Hi there! What actions are you trying to recreate? We have a comprehensive no-code integration with Reddit that already offers quite a large number of actions.

I see you’re looking for a way to fetch Reddit posts—let’s take care of that!

I’ve simplified the process for you. Since OAuth authorization is already integrated into our platform, you can add it as a custom parameter, which REALLY streamlines the entire process.

Here’s what I came up with:

Using the thread ID and subreddit, I successfully retrieved the title, thread content, and comments.

The code is fully functional, so all you need to do is adjust it to suit your needs.

Hope this helps!

As for the code itself, here’s what I’ve done:

/** @CustomParams
{
  "subreddit": {
    "title": "Subreddit",
    "key": "subreddit",
    "description": "The name of the subreddit to fetch the post from",
    "type": "string"
  },
  "post_id": {
    "title": "Post ID",
    "key": "post_id",
    "description": "The ID of the post to fetch",
    "type": "string"
  },
  "oauth_reddit": {
    "title": "Reddit OAuth",
    "key": "oauth_reddit",
    "description": "Select your Reddit OAuth token",
    "type": "connection",
    "required": true
  }
}
*/

import axios from 'axios';

export default async function run({ data }) {
  const subreddit = data.subreddit;
  const post_id = data.post_id;
  const oauth_reddit = data.oauth_reddit;

  if (!subreddit || !post_id || !oauth_reddit) {
    throw new Error('Missing required parameters: subreddit, post_id, or oauth_reddit');
  }

  const url = `https://oauth.reddit.com/r/${subreddit}/comments/${post_id}`;

  try {
    const response = await axios.get(url, {
      headers: {
        'Authorization': `Bearer ${oauth_reddit}`,
        'User-Agent': 'YourApp/0.1 by yourusername'
      }
    });
    return response.data;
  } catch (error) {
    throw new Error(`Failed to fetch Reddit post: ${error.message}`);
  }
}

BTW, you can log in to your Reddit account through the “Authorization” tab or add the Reddit node and authorize through that.

Once done, you’ll be able to select this authorization in your JavaScript.

:v:

Man you are amazing!!!

1 Like

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.