我有一个关于缩放 API 的问题。axiuos中reacjJs中如何获取nodeJs API数据或获取API,
我正在尝试从 reactJs 中的 nodeJs 获取数据,但我得到一个空响应。
我的代码如下。
节点.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', (error, response, 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, null, true, body.access_token);
} else {
// Handle errors, something's gone wrong!
}
}).auth(process.env.clientID, process.env.clientSecret);
return;
}
反应.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)
}
);
}