Open mygethu opened 4 years ago
initialize the Facebook-chat- api
yes you can. first install puppeteer by using npm install puppeteer
. then run the code below
note: not my code, i dont remember who made it but i found it buried in one of the many issues. it generates the appstate.json file, which you then use to login with using this in the login field
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {put the stuff here}
keep the appstate.json file in the root folder, at least thats what i do
const fs = require("fs");
const login = require("facebook-chat-api");
const options = {
userAgent:
"Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Mobile Safari/537.36",
listenEvents: true,
};
var credentials = {email: "", password: ""};
login(credentials, options, (err, api) => {
if (err) {
switch (err.error) {
case "login-approval":
console.log("Enter code > ");
rl.on("line", (line) => {
err.continue(line);
rl.close();
});
break;
default:
console.error(err);
}
return;
}
fs.writeFileSync("appstate.json", JSON.stringify(api.getAppState()));
// Logged in!
});
hope this helps
hi bro Headless browsers often have security issues, Can I use Puppeteer login to initialize the Facebook message api? please help me