I built an application that periodically calls the Twitter API to retrieve tweets for 200 different keywords and store them in a database.
For this purpose, I use the Twitter for Node.js package:
twitterClient.get('search/tweets', {
q : '$' + keyword,
result_type : 'recent',
count : '100'
}
The whole process takes about 4 minutes when performed sequentially.
So I would like to make the Twitter API calls in parallel using Promise.allSettled() to improve performance.
This way the process is much faster (about 20 seconds). The problem is that it causes a lot of errors like "Error: JSON parseError with HTTP Status: 200 OK". So about 25 calls fail.
Why does this happen? How can I solve this problem?
EDIT
I already use Promise.allSettled() to periodically retrieve info about 200 different users:
twitterClient.get('users/show', {
screen_name: userTwitterName
}
In this case I don't have any issue.