Я новичок в API, поэтому точно не знаю, как можно использовать fetch () для получения токена доступа, а затем профиля пользователя. LINE API: [https://developers.line.biz/en/reference/social-api/#issue -access-token] Это все, что мне удалось выяснить. Я могу получить токен доступа через curl, используя git bash, но я понятия не имею, как написать код в 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);
});
}