Forbidden Reddit API call - 在 subreddit 中搜索

Forbidden Reddit API call - Search within subreddit

我正在 API 调用 Reddit API 并收到响应:

{'message': 'Forbidden', 'error': 403}

我的问题是为什么?当我在浏览器中访问此 URL 时,我得到了预期的 JSON:https://www.reddit.com/r/Charlottesville/search.json?q=food&restrict_sr=on

我已经设置了我的身份验证和所有内容,并且已经成功发出了许多 API 请求。我的 headers 是正确的。 当我 运行 以下代码时,我得到 'forbidden' 响应:

#### Search within Subreddit

res = requests.get('https://www.reddit.com/r/Charlottesville/search.json?q=food&restrict_sr=on',
                   headers=headers)

print(res.json())

我的错误很简单。应向 oauth.reddit.com 发出经过正确身份验证的请求,因此我的格式正确的 URL 是:

https://oauth.reddit.com/r/Charlottesville/search.json?q=food&restrict_sr=on

而且有效!