使用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 (将#修改为@)