如何解决使用Amazon MWS提取财务数据时出错
我想将一段时间内的所有财务事件保存在resultArray中。 MWS API不会一次提供所有数据,它会提供nextToken直到有可用数据为止。所以我试图循环直到nextToken为空。
var mwsRequestData = {
Version: '2015-05-01',Action: 'ListFinancialEvents',SellerId: '',MWSAuthToken: '',PostedAfter: '2020-07-01',PostedBefore: '2020-07-02',NextToken: ''
};
let nextToken = '';
let resultArray = [];
amazonMws.finances.search(mwsRequestData)
.then((response) => {
resultArray.push(response.FinancialEvents);
nextToken = response.NextToken;
mwsRequestData.Action = 'ListFinancialEventsByNextToken';
async function process() {
while (nextToken != null && nextToken != '') {
mwsRequestData.NextToken = nextToken;
try {
let response = await amazonMws.finances.search(mwsRequestData);
nextToken = response.NextToken;
resultArray.push(response.FinancialEvents);
} catch {}
}
}
process();
console.log('response',resultArray);
}).catch();
但是这没有用,问题出在循环中,它不是异步运行
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。