javascript - 如何在 Twitter API 请求中使用承载代码?
问题描述
即使在生成承载代码后,我也无法从 twitter 检索数据。一个请求的例子是:
var url = "https://api.twitter.com/1.1/statuses/show.json?id=1125750390664892417";
var bearer = 'Bearer '+ 'myBearer code';
fetch(url, {
method: 'GET',
withCredentials: true,
credentials: 'include',
headers: {
'Authorization': bearer,
'Content-Type': 'application/json'}
}).then((anyResponse) => {
console.log(anyResponse);
}) .catch(error => console.log('Something bad happened ' + error.message)
);
我不明白什么可能是错误的,但它总是失败。我在此页面(https://developer.twitter.com/en/docs/basics/authentication/guides/bearer-tokens)之后获得了不记名代码。但我没有对我的任何密钥进行编码(正如我在这里读到的那样,这是必要的,但 twitter 页面没有这么说)。有人知道我的请求可能出什么问题吗???
谢谢!
解决方案
对我来说,当我使用没有 base64 加密的承载代码时,它终于在 Postman 中工作了。但是,它违背了上面用户评论的文档和漂亮的 python 编码。
我仍然没有在我的 JS 代码中实现,但由于它是 Postman 工作的,我可以想象任何具有相同凭据的 XHR 请求也应该工作。谢谢您的帮助!
推荐阅读
- javascript - 当使用命令请求时,如何获取一个简单的纯文本页面以输出到 Discord?
- javascript - 如何让赛普拉斯返回自定义错误或消息
- haskell - 在 Haskell 中调用状态单子“堆栈”上的函数
- nativescript - 将 Css 类添加到 nativescript-vue 中的按钮点击
- pip - 如何组织我的 python 模块和包
- reactjs - 如何使用 JSX 创建的 SVG 元素作为 Canvas 中的图像源?
- scala - 如何从列中存储值的范围并计算有多少值落入scala中的每个间隔?
- apache-kafka - kafka 代理中处于 CLOSE WAIT 状态的 TCP 端口过多
- python - 如何在 Python 中精确采样传感器信号
- javascript - 如何按关键日期对对象进行排序?