Hello,
my problem is this, help me please
ERR! getUserID TypeError: Cannot read property 'entries' of undefined
ERR! getUserID at /root/olaf-bot/node_modules/facebook-chat-api/src/getUserID.js:43:35
ERR! getUserID at tryCatcher (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/util.js:26:23)
ERR! getUserID at Promise._settlePromiseFromHandler (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:510:31)
ERR! getUserID at Promise._settlePromiseAt (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:584:18)
ERR! getUserID at Promise._settlePromises (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:700:14)
ERR! getUserID at Async._drainQueue (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:123:16)
ERR! getUserID at Async._drainQueues (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:133:10)
ERR! getUserID at Immediate.Async.drainQueues (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:15:14)
ERR! getUserID at runCallback (timers.js:672:20)
ERR! getUserID at tryOnImmediate (timers.js:645:5)
ERR! getUserID at processImmediate [as _immediateCallback] (timers.js:617:5)
ERR! getUserID TypeError: Cannot read property 'entries' of undefined
ERR! getUserID at /root/olaf-bot/node_modules/facebook-chat-api/src/getUserID.js:43:35
ERR! getUserID at tryCatcher (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/util.js:26:23)
ERR! getUserID at Promise._settlePromiseFromHandler (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:510:31)
ERR! getUserID at Promise._settlePromiseAt (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:584:18)
ERR! getUserID at Promise._settlePromises (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:700:14)
ERR! getUserID at Async._drainQueue (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:123:16)
ERR! getUserID at Async._drainQueues (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:133:10)
ERR! getUserID at Immediate.Async.drainQueues (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:15:14)
ERR! getUserID at runCallback (timers.js:672:20)
ERR! getUserID at tryOnImmediate (timers.js:645:5)
ERR! getUserID at processImmediate [as _immediateCallback] (timers.js:617:5)
TypeError: Cannot read property 'entries' of undefined
at /root/olaf-bot/node_modules/facebook-chat-api/src/getUserID.js:43:35
at tryCatcher (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:510:31)
at Promise._settlePromiseAt (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:584:18)
at Promise._settlePromises (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:700:14)
at Async._drainQueue (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:15:14)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5
Looks like the format of the data has changed on facebook's end. Can you run with verbose mode and show us the object you get sent (should be right after "parseAndCheckLogin")?
api.setOptions({logLevel: "verbose"});
I can't seem to reproduce this. Can you show your code?
@Schmavery response with loglevel
info login Logged in
info login Request to reconnect
info login Request to pull 1
info login Request to pull 2
info login Request to thread_sync
info login Done logging in.
verb parseAndCheckLogin for (;;);{"redirect":"https:\/\/web.facebook.com\/ajax\/typeahead\/search.php?fb_dtsg=AQHU0SJBnaI9\u00253AAQFg4qhXqi2q&jazoest=2658172854883746611097735758658170103521131048811310550113&value=bastian+novoa&viewer=100024187667831&rsp=search&context=search&path=\u00252Fhome.php&request_id=9bb0336d-f93e-44cc-ab5b-cf92205b3e76&_rdc=1&__req=3&_rdr"}
ERR! getUserID TypeError: Cannot read property 'entries' of undefined
ERR! getUserID at /root/olaf-bot/node_modules/facebook-chat-api/src/getUserID.js:43:35
ERR! getUserID at tryCatcher (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/util.js:26:23)
ERR! getUserID at Promise._settlePromiseFromHandler (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:510:31)
ERR! getUserID at Promise._settlePromiseAt (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:584:18)
ERR! getUserID at Promise._settlePromises (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:700:14)
ERR! getUserID at Async._drainQueue (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:123:16)
ERR! getUserID at Async._drainQueues (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:133:10)
ERR! getUserID at Immediate.Async.drainQueues (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:15:14)
ERR! getUserID at runCallback (timers.js:672:20)
ERR! getUserID at tryOnImmediate (timers.js:645:5)
ERR! getUserID at processImmediate [as _immediateCallback] (timers.js:617:5)
ERR! getUserID TypeError: Cannot read property 'entries' of undefined
ERR! getUserID at /root/olaf-bot/node_modules/facebook-chat-api/src/getUserID.js:43:35
ERR! getUserID at tryCatcher (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/util.js:26:23)
ERR! getUserID at Promise._settlePromiseFromHandler (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:510:31)
ERR! getUserID at Promise._settlePromiseAt (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:584:18)
ERR! getUserID at Promise._settlePromises (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:700:14)
ERR! getUserID at Async._drainQueue (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:123:16)
ERR! getUserID at Async._drainQueues (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:133:10)
ERR! getUserID at Immediate.Async.drainQueues (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:15:14)
ERR! getUserID at runCallback (timers.js:672:20)
ERR! getUserID at tryOnImmediate (timers.js:645:5)
ERR! getUserID at processImmediate [as _immediateCallback] (timers.js:617:5)
TypeError: Cannot read property 'entries' of undefined
at /root/olaf-bot/node_modules/facebook-chat-api/src/getUserID.js:43:35
at tryCatcher (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:510:31)
at Promise._settlePromiseAt (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:584:18)
at Promise._settlePromises (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/promise.js:700:14)
at Async._drainQueue (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues (/root/olaf-bot/node_modules/facebook-chat-api/node_modules/bluebird/js/main/async.js:15:14)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
@Toohpick my code with problem is
const fs = require("fs");
const login = require("facebook-chat-api");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);
api.setOptions({logLevel: "verbose"});
api.getUserID("Bastian Novoa", (err, data) => {
if(err) return console.error(err);
// Send the message to the best match (best by Facebook's criteria)
var msg = "Hello!"
var threadID = data[0].userID;
console.log(threadID);
});
});
hmm, seems like we're getting a redirect:
{"redirect":"https:\/\/web.facebook.com\/ajax\/typeahead\/search.php?fb_dtsg=AQHU0SJBnaI9\u00253AAQFg4qhXqi2q&jazoest=2658172854883746611097735758658170103521131048811310550113&value=bastian+novoa&viewer=100024187667831&rsp=search&context=search&path=\u00252Fhome.php&request_id=9bb0336d-f93e-44cc-ab5b-cf92205b3e76&_rdc=1&__req=3&_rdr"}
That's annoying. I wonder if this is related to the web.facebook.com issue someone reported a while back. #114 #592
I thought #604 would help fix it, but maybe we also need to catch parsed objects with a single "redirect" key and also redirect in that case. @Theblood want to try?
my solution is #633
@Theblood Can we just handle the redirect when we see it? I don't think this web.facebook thing applies to everyone right now.
@Schmavery Of course you can, we just have to take the object of redirection to handle it, this will see with time for now analyze the other functions.
@Theblood I don't completely understand. I'm imagining adding a check for a "redirect" field in the object that is parsed near the end of https://github.com/Schmavery/facebook-chat-api/blob/733dd6dd5739e67a214077b9a18412f80b61de0b/utils.js#L982 and having parseAndCheckLogin call itself recursively with the new url if so. Something along those lines anyway.
@Schmavery Adding
if (res.redirect && data.request.method === "GET") {
return defaultFuncs
.get(res.redirect, ctx.jar)
.then(parseAndCheckLogin(ctx, defaultFuncs));
}
after https://github.com/Schmavery/facebook-chat-api/blob/733dd6dd5739e67a214077b9a18412f80b61de0b/utils.js#L1046-L1055 fixed this issue for me on the affected network. I also tested on a network that didn't have this issue and it still works fine. Let me know if it is indeed the desired fix you suggested so I can submit a PR with it.
That looks like what I was thinking, I think we could definitely accept a PR for this @Toohpick. Thanks for investigating and testing!
Thanks for the feedback, @Schmavery. The PR has been submitted.
Most helpful comment
@Theblood Can we just handle the redirect when we see it? I don't think this web.facebook thing applies to everyone right now.