Skip to content

Instantly share code, notes, and snippets.

@benkaiser
Created November 9, 2016 11:50
Show Gist options
  • Save benkaiser/2438636fa65f8f9238fae4616d2ba4dd to your computer and use it in GitHub Desktop.
Save benkaiser/2438636fa65f8f9238fae4616d2ba4dd to your computer and use it in GitHub Desktop.
facebook-chat-api getThreadHistory broken
// es6 code, run with `FB_EMAIL=email FB_PASSWORD=password node --harmony index.js`
let login = require('facebook-chat-api');
let util = require('util');
let async = require('async');
// Create simple echo bot
login({ email: process.env.FB_EMAIL, password: process.env.FB_PASSWORD }, (err, api) => {
if (err) return console.error(err);
api.getThreadInfo('SOME_BIG_THREAD_ID', (err, info) => {
console.log(info);
let iteration = 0;
let chunkSize = 10000;
async.until(() => (iteration * chunkSize) > info.messageCount, (callback) => {
api.getThreadHistory(
'100004708478156',
iteration * chunkSize,
(iteration + 1) * chunkSize,
null,
(err, history) => {
console.log(err);
console.log(history.length);
console.log(history[0]);
console.log(history[history.length - 1]);
console.log(iteration);
iteration++;
callback();
});
}, () => {
console.log('done all!');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment