如何解决如何在 axiuos 中的 reacj js 中获取 nodejs api 数据或 fetch api
我有一个关于缩放 API 的问题。 如何在 axiuos 或 fetch API 中获取 reacjJs 中的 nodeJs API 数据,
我正在尝试从 reactJs 中的 nodeJs 获取数据,但我得到了一个空响应。
我的代码如下。
Node.js:
router.get('/auth',function(req,res,next) {
if (req.query.code) {
let url = 'https://zoom.us/oauth/token?grant_type=authorization_code&code=' + req.query.code + '&redirect_uri=' + process.env.redirectURL;
request.post(url,(error,response,body) => {
// Parse response to JSON
body = JSON.parse(body);
console.log(`access_token: ${body.access_token}`);
console.log(`refresh_token: ${body.refresh_token}`);
if (body.access_token) {
request.get('https://api.zoom.us/v2/users/me',body) => {
if (error) {
console.log('API Response Error: ',error)
} else {
body = JSON.parse(body);
console.log('API call ',body);
var JSONResponse = '<pre><code>' + JSON.stringify(body,null,2) + '</code></pre>'
res.send(`
<style>
</style>
<h2>${body.first_name} ${body.last_name}</h2>
<p>${body.role_name},${body.company}</p>
${JSONResponse}
`);
}
}).auth(null,true,body.access_token);
} else {
// Handle errors,something's gone wrong!
}
}).auth(process.env.clientID,process.env.clientSecret);
return;
}
React.js:
componentDidMount() {
const url = 'http://localhost:3000/api';
axios.post(
url,{
path: '/v2/users/info@data.nyc',methode: 'GET'
}
)
.then((response) => {
console.log(response)
},(error) => {
console.log(error)
}
);
}
解决方法
您的 axios 调用不正确。试试下面。
componentDidMount() {
const url = 'http://localhost:3000/api';
axios
.get(url + '/v2/users/info@data.nyc')
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
});
}
,
我建议你修复 axios 页面:
试试这个:
const url = 'http://localhost:3000/api';
const zoom = () => {
Axios.get(url + '/v2/users/info@data.nyc')
.then((response) => {
console.log(response)
})
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。