Reddit API 返回 HTTP 403 [英] Reddit API returns HTTP 403

查看:88
本文介绍了Reddit API 返回 HTTP 403的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循 https://github.com/reddit/reddit/中描述的 OAuth2 登录流程wiki/OAuth2 我到了 POST 到 https://www.reddit.com/api/v1/access_token 返回如下内容:

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': '*****'}

那我做

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

使用此标题:

Authorization: bearer *****

响应是 HTTP 403 Unauthorized.但为什么?很明显,访问令牌具有身份"范围.还记录了/api/v1/me 调用仅需要此范围.(参见 https://www.reddit.com/dev/api/oauth#GET_api_v1_me )

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 )

那么为什么我会收到 http 403?

So why am I getting http 403?

推荐答案

我遇到了与您描述的完全相同的问题.就我而言,我通过在请求标头中添加 faux 用户代理字符串来解决 403.

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.

在我的例子中,使用 C# 的 HttpClient,这会像这样进行:

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");
    ...
}

这篇关于Reddit API 返回 HTTP 403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆