javascript - 如何在 JavaScript 中从 LINE api 获取用户数据?
问题描述
我是 API 新手,所以我不完全知道如何使用 fetch() 获取访问令牌,然后获取用户配置文件。LINE API:[https://developers.line.biz/en/reference/social-api/#issue-access-token] 到目前为止,这就是我能想到的。我可以使用 git bash 通过 curl 获取访问令牌,但我不知道如何在 JS 中编写代码来获取 json 数据。
function generate(e){
e.preventDefault();
fetch(('https://cors-anywhere.herokuapp.com/'+'https://api.line.me/v2/oauth/accessToken'), {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: JSON.stringify({
grant_type: 'authorization_code',
client_id: 'my_id',
client_secret: 'my_client_secret',
code: 'code',
redirect_uri: 'the link direct to'
})
})
.then((res) => console.log(res.json()))
.catch((err) => {
console.log(err);
});
}
解决方案
推荐阅读
- webpack - WebPack - 在重新编译主模块之前等待子模块编译
- python - 如何为 ttk 小部件的不同部分设置样式?
- python - pint:将地理 CRS 度数转换为海里
- c++ - 根据贡献指南构建 Boost.Hana 时出错
- python - 打印经过时间并通过单击按钮重置的计时器
- angular - 如何在 Angular 项目中正确导入 bootstrap scss 以避免重复样式?
- websocket - Websocket连接在同一场景中断开,页面上无法形成以下操作
- google-sheets - 如何在范围内使用 INDIRECT?
- python - Pyautogui 在我导入时更改我的窗口大小
- eos - 如何用两个以上的钱包签署 WAX 交易