Hi all, if somebody knows hot to get all Direct Messages, not just the last, please help!
My code is the next:
Client.Session.create(device, storage, 'user', 'password')
.then(function(session) {
var accountId = storage.getAccountId() .then(function(accountId){ console.log(accountId); return
accountId;});
var feed = new Client.Feed.Inbox(session, accountId);
feed.get()
.then(function(results) {
return results[0].items;
})
.then(function (items) {
console.log(items[0]._params.text);
})
results[0].items; - returns array with only the last direct message, while there should be a lot of messages.
How to get them all?
I am appreciated for any help
I made this https://github.com/Elyx0/instagram-inbox-api/blob/master/src/instapi.js to read them, but I tried with an account with 3000+ messages in a thread and It wasn't able to finish...
While doing the
const tFeed = new Client.Feed.ThreadItems(session, threadId);
const tFeedIt = await tFeed.all();
Was around iteration 226 with allResults.length ~ 4495
Result:
Error: read ECONNRESET
at exports._errnoException (util.js:1026:11)
at TLSWrap.onread (net.js:607:25)
"RequestError: Error: read ECONNRESET
at new RequestError (/instadmback/node_modules/instagram-private-api/node_modules/request-promise/lib/errors.js:11:15)
at Request.RP$callback [as _callback] (/instadmback/node_modules/instagram-private-api/node_modules/request-promise/lib/rp.js:60:32)
at self.callback (/instadmback/node_modules/request/request.js:188:22)
at emitOne (events.js:115:13)
at Request.emit (events.js:210:7)
at Request.onRequestError (/instadmback/node_modules/request/request.js:884:8)
at emitOne (events.js:115:13)
at ClientRequest.emit (events.js:210:7)
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at emitOne (events.js:115:13)
at TLSSocket.emit (events.js:210:7)
at emitErrorNT (internal/streams/destroy.js:62:8)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickDomainCallback (internal/process/next_tick.js:198:9)"
I think it might be possible to catch it either directly from the lib or with a try catch when calling the .all(), getting the current cursor from the error and restarting from there...
Actually the 2nd option will not work as we would be losing the already fetched results... since only the error gets thrown, not the current fetching state
Ok I changed feed-base.js to catch and retry and I was able to finish getting 12407 messages, phew!
// If ParseError, we assume that this is 403 forbidden HTML page, caused by "Too many requests". Just take a pause and retry.
.catch(Exceptions.ParseError, function () {
// Every consecutive ParseError makes delay befor new request longer. Otherwise we will never reach the end.
that.parseErrorsMultiplier++;
// When delay time is beyond reasonable, throw exception.
if(that.parseErrorsMultiplier > parameters.maxErrors)
throw new Exceptions.RequestsLimitError;
return Promise.resolve([]).delay(parameters.pause * that.parseErrorsMultiplier)
})
.catch(Exceptions.RequestError, function () {
// Every consecutive ParseError makes delay befor new request longer. Otherwise we will never reach the end.
that.parseErrorsMultiplier++;
// When delay time is beyond reasonable, throw exception.
if(that.parseErrorsMultiplier > parameters.maxErrors)
throw new Exceptions.RequestsLimitError;
return Promise.resolve([]).delay(parameters.pause * that.parseErrorsMultiplier)
})
.then(function (results) {
Thanks @Elyx0 it helps!
This should go as a pull request! :)
Hi @Elyx0 ! What's your recommendation for "parameters.pause" value ?
Most helpful comment
Ok I changed feed-base.js to catch and retry and I was able to finish getting
12407messages, phew!