javascript - 无法使用 Web 应用从 reddit 获取 access_token
问题描述
我想access_token
从 Reddit 获得一个在我的代码中使用,但不断收到有关不受支持的授权类型的 401 错误。这是代码(过滤了个人内容):
const fetch = require('node-fetch');
const FormData = require('form-data');
let data = new FormData()
data.append('code', 'temporary_code')
data.append('grant_type', "authorization_code")
data.append('redirect_uri', "http://localhost")
fetch('https://www.reddit.com/api/v1/access_token', {
method: 'post',
body: data,
headers: {'Authorization': `Basic ${Buffer.from('client_id:client_secret').toString('base64')}`, 'content-type': 'application/x-www-form-urlencoded'}
})
.then(res => res.json())
.then(console.log)
我不断尝试换掉content-type
我的代码的值(主要是移动到不同的地方)。我什至尝试使用Postman
发出帖子请求,但也失败了。我浏览了网络(主要是关于同一问题的 reddit 问题,但使用不同的应用程序类型或不同的编程语言)试图得到答案。我什至多次尝试在谷歌上搜索我的问题,但都失败了。这是我得到的确切错误:
{ message: 'Unauthorized', error: 401 }
在编写代码时,我使用Reddit Wiki
来确保我做的一切都是正确的。我注意到我有unsupported_grant_type
错误,最终我放弃了尝试修复自己。现在,我要求大家尝试帮助甚至回答我的问题。提前非常感谢。
解决方案
推荐阅读
- ruby-on-rails - 处理事务内的唯一约束异常
- html - 为日期创建范围滑块
- vba - Outlook 2010 - 从个人邮件发送电子邮件之前的警告弹出窗口
- amazon-web-services - 我可以通过 sqldeveloper 连接到 AWS RDS,但不能通过 Java 应用程序
- sql - 在同一张表内计算
- android - 如何在 RecyclerView 的水平滚动中使卡片半可见,类似于图像中所示
- r - 如何用 ggplot 绘制用矩阵函数生成的列联表?
- android - 在 Android 应用中使用 WRITE_CALL_LOG 权限在 Play 商店中收到警告
- python - 正则表达式匹配大写/特殊/unicode/越南字符
- javascript - 为什么当我在回调函数中返回一个数组而不是一些原语时,map 的工作方式不同?