我正在尝试从api获取访问令牌...但是我得到未定义的json数据请帮助..我在requestToken()中获得了正确的数据,但是当它将数据返回给route.js时..
access.js -------------------------------------------- -------------------------------------------------- ------------------------
exports.requestToken = function () {
var options = {
url: '---URL---',
method: 'POST',
form: {
access_key: 'xxxxxx',
secret_key: 'xxxxxx',
app_id: 'xxxxx',
device_id: 'xxxxx'
}
};
request(options, function(error, res, body) {
//console.log(JSON.parse(body)) ---> correct data
//here s problem
return JSON.parse(body);
});
}
route.js -------------------------------------------- -------------------------------------------------- ---------------------------
route.get('/get', function(req, res)
{ //undefined
body = jsonBody.requestToken();
console.log(body);
body = jsonBody.reqRecentMatches(token);
//console.log(body);
//res.json(body);
}