Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reddit API returns HTTP 403

Following the OAuth2 login flow described at https://github.com/reddit/reddit/wiki/OAuth2 I got to the point where POST-ing to https://www.reddit.com/api/v1/access_token returns something like this:

{'token_type': 'bearer', 'expires_in': 3600, 'scope': 'identity', 'access_token': '*****'}

Then I do

GET  https://oauth.reddit.com/api/v1/me

With this header:

Authorization: bearer *****

The response is HTTP 403 Unauthorized. But why? It is clear that the access token has 'identity' scope. It is also documented that the /api/v1/me call requires this scope only. (See https://www.reddit.com/dev/api/oauth#GET_api_v1_me )

So why am I getting http 403?

like image 614
nagylzs Avatar asked Feb 02 '17 17:02

nagylzs


1 Answers

I was experiencing the exact same issue as you described. In my case, I resolved the 403 by adding a faux user agent string in the request headers.

In my case, using HttpClient of C#, this proceeds like so:

using (var client = new HttpClient())
{
    client.DefaultRequestHeaders.Add("User-Agent", "MockClient/0.1 by Me");
    ...
}
like image 126
ne1410s Avatar answered Nov 15 '22 05:11

ne1410s