我正在使用Twilio的Sync Library设置同步应用程序。出于某种原因,REST API方法似乎都不起作用。也就是说,我无法通过运行时函数获得任何同步方法到console.log()。
但是,我可以使用console.log()纯文本。
这是我的代码:
exports.handler = function(context, event, callback) {
// 0. Init
// const phoneNumber = event.phoneNumber;
const issueLimit = 3; // CHANGE IF NEEDED
const listName = 'issues';
const twilioClient = context.getTwilioClient();
// 1. List all lists
twilioClient.sync.services(context.SYNC_SERVICE_SID)
.syncLists
.list({limit: 20})
.then(syncLists => syncLists.forEach(s => console.log(s.sid)));
// 2. return true if quota reached
console.log("Got to here");
// 3. return false
callback(null, undefined);
};
似乎要执行的唯一代码是'console.log(“Got to here”);'。我也没有收到任何错误消息。
任何指导都真诚地感谢。
当你看到.then()
,这是一个承诺,你可以在这里阅读更多关于这个https://www.twilio.com/blog/2016/10/guide-to-javascript-promises.html
换句话说,JavaScript引擎转到你的步骤2.
然后3.
而不等待1.
完成。因为你在callback(null, undefined);
的第3步返回,你将看不到日志。
所以,你必须在callback()
中移动.then()
,如下所示:
exports.handler = function (context, event, callback) {
// 0. Init
// const phoneNumber = event.phoneNumber;
const issueLimit = 3; // CHANGE IF NEEDED
const listName = 'issues';
const twilioClient = context.getTwilioClient();
// 1. List all lists
twilioClient.sync.services(context.SYNC_SERVICE_SID)
.syncLists
.list({ limit: 20 })
.then(
function (syncLists) {
console.log("Got to here");
syncLists.forEach(s => console.log(s.sid));
callback(null, undefined);
}
);
};