javascript – Promise返回undefined

我知道你不能使异步函数同步运行但是
如何在我的承诺链中添加某种订单?

一个结果依赖于先前的promise值,当没有发生时,我得到一个未定义的错误.这是一个http请求,因此它依赖于外部因素,例如我的连接可以执行请求的速度等等.

module.exports.movieCheck = function(authToken) {
return request({
    method : 'GET',
    uri : 'https://graph.facebook.com/' + profileID + '/posts?fields=message&limit=25&' + authToken
    }).spread(function (response, body) {
        console.log('https://graph.facebook.com/' + profileID + '/posts?fields=message&limit=25&' + authToken);
        return body;
    }, function(e) {
        console.log(e);
});
};

我调用上面的方法如下.但是console.log返回undefined.

movieCheck.getToken()
.then(function(token) {
  movieCheck.movieCheck(token);
})
.then(function(movies) {
  console.log(movies); //should print json data
});   

终端打印

undefined
https://graph.facebook.com/.../posts?fields=message&limit=25&access_token=....

解决方法:

尝试从第一个回调中返回承诺

movieCheck.getToken()
    .then(function (token) {
    return movieCheck.movieCheck(token);
}).then(function (movies) {
    console.log(movies); //should print json data
});

相关文章

最后的控制台返回空数组.控制台在ids.map函数完成之前运行va...
我正在尝试将rxJava与我已经知道的内容联系起来,特别是来自J...
config.jsconstconfig={base_url_api:"https://douban....
我正在阅读MDN中的javascript,并且遇到了这个谈论承诺并且不...
config.jsconstconfig={base_url_api:"https://douban....
这是我的代码main.cpp:#include<string>#include<...