2

我已经针对 Reddit 帐户完成了我的第三方应用程序的 oauth 流程,并且我已经获得了该帐户的访问令牌。

现在我的下一个问题是

如何使用访问令牌获取帐户的 subreddits

我似乎无法弄清楚这一点。

有谁知道终点?

谢谢

4

1 回答 1

3

Reddit OAuth 文档说,对于/subreddits/mine/(where)端点,subredditsOAuth 范围是必要的。

为用户获取该范围后,您可以使用以下代码片段访问用户订阅的子版块列表:

查看用户 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`,
  };
});
于 2022-01-03T23:28:05.183 回答