2

I have completed the oauth flow for my third party app against a Reddit account and I've gotten the access token for the account.

Now my next issue is

How can I fetch the subreddits for an account using the access token

I can't seem to figure out the endpoint for that.

Does anyone know the endpoint for that?

Thank you

ololo
  • 1,326
  • 2
  • 14
  • 47

1 Answers1

3

The Reddit OAuth Docs say that for the /subreddits/mine/(where) endpoint, the subreddits OAuth scope is necessary.

Once that scope is acquired for a user, you can use the following snippets of code to access the list of subscribed subreddits for the user:

View a users subreddits                                                                                 View in Fusebit
  // Demonstrate using snooclient and Fusebit
  const subscriptions = await redditClient.getSubscriptions().fetchAll();

  // OR fetch the first page using a raw HTTP request
  // - the User-Agent is necessary, don't forget it!
  const access_token = redditClient.fusebit.credentials.access_token;
  const httpSubs = await superagent.get(
    'https://oauth.reddit.com/subreddits/mine/subscriber')
    .set('Authorization', `Bearer ${access_token}`)
    .set('User-Agent', 'Fusebit Integration');

  const length = httpSubs.body.data.children.length;
  ctx.body = {
    usingSnoo: `User has ${subscriptions.length} subreddits`,
    usingHttp: `The first page has ${length} subreddits`,
  };
});
Benn
  • 101
  • 1
  • 4