-
Notifications
You must be signed in to change notification settings - Fork 21
/
login.js
34 lines (32 loc) · 1.09 KB
/
login.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const fs = require("fs");
const login = require("facebook-chat-api");
const readline = require("readline");
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
console.log('Enter email > ');
rl.on('line', (email) => {
console.log('Enter password > ');
rl.on('line', (password) => {
login({email, password}, {}, (err, api) => {
if(err) {
switch (err.error) {
case 'login-approval':
console.log('If you were sent a code, enter it here. If you were asked to approve your login via another device, approve it, choose "save browser", and just hit enter here> ');
rl.on('line', (code) => {
err.continue(code);
rl.close();
});
break;
default:
console.error(err);
}
} else {
fs.writeFileSync('appstate.json', JSON.stringify(api.getAppState()));
console.log("Success! App state written to file. You should be able to ignore other errors as long as appstate.json was written.");
process.exit();
}
});
});
});