Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Please help me on how to successfully login. #870

Open
AFalseHuman opened this issue Mar 19, 2021 · 25 comments
Open

Please help me on how to successfully login. #870

AFalseHuman opened this issue Mar 19, 2021 · 25 comments

Comments

@AFalseHuman
Copy link

{ error: 'Wrong username/password.' }

Always prompt after I login , password is correct and also email.

@1601
Copy link

1601 commented Mar 21, 2021

same here

@floviolleau
Copy link

floviolleau commented Mar 23, 2021

Hi,

Same here. There is an issue with headers location I guess:

Around line 168

log.info("login", "Logging in..."m);
    return utils
      .post("https://www.facebook.com/login.php?login_attempt=1&lwv=110", jar, form)
      .then(utils.saveCookies(jar))
      .then(function(res) {
        var headers = res.headers;
        if (!headers.location) {
          throw {error: "Wrong username/password."};
        }

...

Here is the console log of res.headers:

res {
  'x-fb-rlafr': '0',
  'cache-control': 'private, no-cache, no-store, must-revalidate',
  expires: 'Sat, 01 Jan 2000 00:00:00 GMT',
  'access-control-allow-credentials': 'true',
  'content-encoding': 'gzip',
  'x-frame-options': 'DENY',
  'access-control-allow-origin': 'https://www.facebook.com',
  'access-control-expose-headers': 'X-FB-Debug, X-Loader-Length',
  pragma: 'no-cache',
  vary: 'Origin, Accept-Encoding',
  'strict-transport-security': 'max-age=15552000; preload',
  'access-control-allow-methods': 'OPTIONS',
  'set-cookie': [
    '<redacted>; expires=Thu, 23-Mar-2023 22:35:27 GMT; Max-Age=63072000; path=/; domain=.facebook.com; secure; httponly',
    '<redacted>; expires=Mon, 21-Jun-2021 22:35:25 GMT; Max-Age=7775998; path=/; domain=.facebook.com; secure; httponly'
  ],
  'content-security-policy': "default-src * data: blob: 'self';script-src *.facebook.com *.fbcdn.net *.facebook.net *.google-analytics.com *.virtualearth.net *.google.com 127.0.0.1:* *.spotilocal.com:* 'unsafe-inline' 'unsafe-eval' blob: data: 'self';style-src data: blob: 'unsafe-inline' *;connect-src *.facebook.com facebook.com *.fbcdn.net *.facebook.net *.spotilocal.com:* wss://*.facebook.com:* https://fb.scanandcleanlocal.com:* attachment.fbsbx.com ws://localhost:* blob: *.cdninstagram.com 'self';block-all-mixed-content;upgrade-insecure-requests;",
  'x-xss-protection': '0',
  'x-content-type-options': 'nosniff',
  'content-type': 'text/html; charset="utf-8"',
  'x-fb-debug': '<redacted>',
  date: 'Tue, 23 Mar 2021 22:35:28 GMT',
  priority: 'u=3,i',
  'alt-svc': 'h3-29=":443"; ma=3600,h3-27=":443"; ma=3600',
  'transfer-encoding': 'chunked',
  connection: 'keep-alive'
}

Seems to be same as #867

@CRAKZOR
Copy link

CRAKZOR commented Mar 25, 2021

you can login. Log in from browser incognito, grab cookies, and replace each in appstate.json.

The problem is the new encpass field. The algorithm is in another get response on page load.

It's the get response w/

...
__d("FBBrowserPasswordEncryption", ["EnvelopeEncryption", "regeneratorRuntime", "tweetnacl-util"], (function(a, b, c, d, e, f) {
  "use strict";
  f.encryptPassword = a;
  function a(a, c, d, e) {
      var f,
          g,
          h,
          i,
          j;
      return b("regeneratorRuntime").async(function(k) {
          while (1)
              switch (k.prev = k.next) {
              case 0:
                  f = "#PWD_BROWSER";
                  g = 5;
                  h = b("tweetnacl-util").decodeUTF8(d);
                  i = b("tweetnacl-util").decodeUTF8(e);
                  k.next = 6;
                  return b("regeneratorRuntime").awrap(b("EnvelopeEncryption").encrypt(a, c, h, i));
              case 6:
                  j = k.sent;
                  return k.abrupt("return", [f, g, e, b("tweetnacl-util").encodeBase64(j)].join(":"));
              case 8:
              case "end":
                  return k.stop()
              }
      }, null, this)
  }
}), null);
...

@adox
Copy link

adox commented Mar 29, 2021

@CRAKZOR could you share example appstate.json? I was not able to login, would like to have some template to paste cookies into

@adox
Copy link

adox commented Mar 30, 2021 via email

@CongTuHaoHoa
Copy link

CongTuHaoHoa commented Apr 6, 2021

Hi, I just got my solution today.
Please follow those step to make thing right.

Step 1: Login your Facebook account on the browser.
Step 2: Get the cookies from the site as json file. You can use this bad boy to get it.(https://chrome.google.com/webstore/detail/j2team-cookies/okpidcojinmlaakglciglbpcpajaibco)
Step 3: Open it, you should see the first line like {"url":"https://www.facebook.com","cookies":. Copy all of that.
Step 4: Create a "appState.json" paste all you got into this file. Then replace all "name" to "key"
Step 5: Add it in to your project by fs read file sync. The structure you must use for login is the JSON object you got from the appState.json and done forget to save it when ever you try to login again. To refresh the new appState.

Done and worked for me. Hope you can do it too

@AFalseHuman
Copy link
Author

AFalseHuman commented Apr 7, 2021

Hi, I just got my solution today.
Please follow those step to make thing right.

Step 1: Login your Facebook account on the browser.
Step 2: Get the cookies from the site as json file. You can use this bad boy to get it.(https://chrome.google.com/webstore/detail/j2team-cookies/okpidcojinmlaakglciglbpcpajaibco)
Step 3: Open it, you should see the first line like {"url":"https://www.facebook.com","cookies":. Just use the array of the cookies element, then save that cookies as a "appstate.json" file
Step 4: Add it in to your project.
Step 5: Open the index.js (of this library source). You should see the function loginHelper. At the first "if" line. You should see some like var str = c.value + "=". Edit the c.value to c.name.

Done and worked for me. Hope you can do it too

What's the structure for the login details ? is it still {email: "FB_EMAIL", password: "FB_PASSWORD"} ? or its different

@ghost
Copy link

ghost commented Apr 7, 2021

You don't need it if you use appstate.

@thangphamnd123
Copy link

I got this error when using cookies.
@CongTuHaoHoa: Do you have any idea?

ERR! login Error: Cookie not in this host's domain. Cookie:www.facebook.com Request:www.messenger.com
ERR! login at CookieJar.setCookie (D:\PERSONAL\Learning\fbgroupbot\node_modules\tough-cookie\lib\cookie.js:1037:13)
ERR! login at CookieJar.setCookieSync (D:\PERSONAL\Learning\fbgroupbot\node_modules\tough-cookie\lib\cookie.js:1452:18)
ERR! login at RequestJar.setCookie (D:\PERSONAL\Learning\fbgroupbot\node_modules\request\lib\cookies.js:25:20)
ERR! login at D:\PERSONAL\Learning\fbgroupbot\node_modules\facebook-chat-api\utils.js:1116:11
ERR! login at Array.forEach ()
ERR! login at D:\PERSONAL\Learning\fbgroupbot\node_modules\facebook-chat-api\utils.js:1111:13
ERR! login at tryCatcher (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\util.js:16:23)
ERR! login at Promise._settlePromiseFromHandler (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:547:31)
ERR! login at Promise._settlePromise (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:604:18)
ERR! login at Promise._settlePromise0 (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:649:10)
ERR! login at Promise._settlePromises (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:729:18)
ERR! login at Promise._fulfill (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:673:18)
ERR! login at Promise._resolveCallback (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:466:57)
ERR! login at Promise._settlePromiseFromHandler (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:559:17)
ERR! login at Promise._settlePromise (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:604:18)
ERR! login at Promise._settlePromise0 (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:649:10)
ERR! login Error: Cookie not in this host's domain. Cookie:www.facebook.com Request:www.messenger.com
ERR! login at CookieJar.setCookie (D:\PERSONAL\Learning\fbgroupbot\node_modules\tough-cookie\lib\cookie.js:1037:13)
ERR! login at CookieJar.setCookieSync (D:\PERSONAL\Learning\fbgroupbot\node_modules\tough-cookie\lib\cookie.js:1452:18)
ERR! login at RequestJar.setCookie (D:\PERSONAL\Learning\fbgroupbot\node_modules\request\lib\cookies.js:25:20)
ERR! login at D:\PERSONAL\Learning\fbgroupbot\node_modules\facebook-chat-api\utils.js:1116:11
ERR! login at Array.forEach ()
ERR! login at D:\PERSONAL\Learning\fbgroupbot\node_modules\facebook-chat-api\utils.js:1111:13
ERR! login at tryCatcher (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\util.js:16:23)
ERR! login at Promise._settlePromiseFromHandler (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:547:31)
ERR! login at Promise._settlePromise (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:604:18)
ERR! login at Promise._settlePromise0 (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:649:10)
ERR! login at Promise._settlePromises (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:729:18)
ERR! login at Promise._fulfill (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:673:18)
ERR! login at Promise._resolveCallback (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:466:57)
ERR! login at Promise._settlePromiseFromHandler (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:559:17)
ERR! login at Promise._settlePromise (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:604:18)
ERR! login at Promise._settlePromise0 (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:649:10)
Error: Cookie not in this host's domain. Cookie:www.facebook.com Request:www.messenger.com
at CookieJar.setCookie (D:\PERSONAL\Learning\fbgroupbot\node_modules\tough-cookie\lib\cookie.js:1037:13)
at CookieJar.setCookieSync (D:\PERSONAL\Learning\fbgroupbot\node_modules\tough-cookie\lib\cookie.js:1452:18)
at RequestJar.setCookie (D:\PERSONAL\Learning\fbgroupbot\node_modules\request\lib\cookies.js:25:20)
at D:\PERSONAL\Learning\fbgroupbot\node_modules\facebook-chat-api\utils.js:1116:11
at Array.forEach ()

@CongTuHaoHoa
Copy link

I got this error when using cookies.
@CongTuHaoHoa: Do you have any idea?

ERR! login Error: Cookie not in this host's domain. Cookie:www.facebook.com Request:www.messenger.com
ERR! login at CookieJar.setCookie (D:\PERSONAL\Learning\fbgroupbot\node_modules\tough-cookie\lib\cookie.js:1037:13)
ERR! login at CookieJar.setCookieSync (D:\PERSONAL\Learning\fbgroupbot\node_modules\tough-cookie\lib\cookie.js:1452:18)
ERR! login at RequestJar.setCookie (D:\PERSONAL\Learning\fbgroupbot\node_modules\request\lib\cookies.js:25:20)
ERR! login at D:\PERSONAL\Learning\fbgroupbot\node_modules\facebook-chat-api\utils.js:1116:11
ERR! login at Array.forEach ()
ERR! login at D:\PERSONAL\Learning\fbgroupbot\node_modules\facebook-chat-api\utils.js:1111:13
ERR! login at tryCatcher (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\util.js:16:23)
ERR! login at Promise._settlePromiseFromHandler (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:547:31)
ERR! login at Promise._settlePromise (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:604:18)
ERR! login at Promise._settlePromise0 (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:649:10)
ERR! login at Promise._settlePromises (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:729:18)
ERR! login at Promise._fulfill (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:673:18)
ERR! login at Promise._resolveCallback (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:466:57)
ERR! login at Promise._settlePromiseFromHandler (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:559:17)
ERR! login at Promise._settlePromise (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:604:18)
ERR! login at Promise._settlePromise0 (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:649:10)
ERR! login Error: Cookie not in this host's domain. Cookie:www.facebook.com Request:www.messenger.com
ERR! login at CookieJar.setCookie (D:\PERSONAL\Learning\fbgroupbot\node_modules\tough-cookie\lib\cookie.js:1037:13)
ERR! login at CookieJar.setCookieSync (D:\PERSONAL\Learning\fbgroupbot\node_modules\tough-cookie\lib\cookie.js:1452:18)
ERR! login at RequestJar.setCookie (D:\PERSONAL\Learning\fbgroupbot\node_modules\request\lib\cookies.js:25:20)
ERR! login at D:\PERSONAL\Learning\fbgroupbot\node_modules\facebook-chat-api\utils.js:1116:11
ERR! login at Array.forEach ()
ERR! login at D:\PERSONAL\Learning\fbgroupbot\node_modules\facebook-chat-api\utils.js:1111:13
ERR! login at tryCatcher (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\util.js:16:23)
ERR! login at Promise._settlePromiseFromHandler (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:547:31)
ERR! login at Promise._settlePromise (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:604:18)
ERR! login at Promise._settlePromise0 (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:649:10)
ERR! login at Promise._settlePromises (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:729:18)
ERR! login at Promise._fulfill (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:673:18)
ERR! login at Promise._resolveCallback (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:466:57)
ERR! login at Promise._settlePromiseFromHandler (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:559:17)
ERR! login at Promise._settlePromise (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:604:18)
ERR! login at Promise._settlePromise0 (D:\PERSONAL\Learning\fbgroupbot\node_modules\bluebird\js\release\promise.js:649:10)
Error: Cookie not in this host's domain. Cookie:www.facebook.com Request:www.messenger.com
at CookieJar.setCookie (D:\PERSONAL\Learning\fbgroupbot\node_modules\tough-cookie\lib\cookie.js:1037:13)
at CookieJar.setCookieSync (D:\PERSONAL\Learning\fbgroupbot\node_modules\tough-cookie\lib\cookie.js:1452:18)
at RequestJar.setCookie (D:\PERSONAL\Learning\fbgroupbot\node_modules\request\lib\cookies.js:25:20)
at D:\PERSONAL\Learning\fbgroupbot\node_modules\facebook-chat-api\utils.js:1116:11
at Array.forEach ()

Ông đổi hết field "name" trong cookie này thành "key" là được nha

@CongTuHaoHoa
Copy link

Hi, I just got my solution today.
Please follow those step to make thing right.

Step 1: Login your Facebook account on the browser.
Step 2: Get the cookies from the site as json file. You can use this bad boy to get it.(https://chrome.google.com/webstore/detail/j2team-cookies/okpidcojinmlaakglciglbpcpajaibco)
Step 3: Open it, you should see the first line like {"url":"https://www.facebook.com","cookies":. Just use the array of the cookies element, then save that cookies as a "appstate.json" file
Step 4: Add it in to your project.
Step 5: Open the index.js (of this library source). You should see the function loginHelper. At the first "if" line. You should see some like var str = c.value + "=". Edit the c.value to c.name.

Done and worked for me. Hope you can do it too

What's the structure for the login details ? is it still {email: "FB_EMAIL", password: "FB_PASSWORD"} ? or its different

You can logged from appstate. And everytime you have to change your account. You must to change your appstate too

@CongTuHaoHoa
Copy link

CongTuHaoHoa commented Apr 8, 2021

I just create a video for help. Please turn on your subtitle b/c my English is bad.
Here is it : https://www.youtube.com/watch?v=y9_yd5a3scM

@thangphamnd123
Copy link

@CongTuHaoHoa : Thank ông nhé. Tôi đổi xong đã login được rồi.

@trgkyle
Copy link

trgkyle commented Apr 10, 2021

I just create a videos for help. Please turn on your subtitle b/c my English is bad.
Here is it : https://www.youtube.com/watch?v=y9_yd5a3scM

thanks ô nhé vậy hàm login bằng email với pass word của thư viện bị lỗi rồi

@BadAimWeeb
Copy link
Contributor

I just create a videos for help. Please turn on your subtitle b/c my English is bad.
Here is it : https://www.youtube.com/watch?v=y9_yd5a3scM

thanks ô nhé vậy hàm login bằng email với pass word của thư viện bị lỗi rồi

lỗi lâu rồi.
#862#issuecomment-762436951

@trungtd-1561
Copy link

@CongTuHaoHoa em login thành công rồi nhưng sau đó vẫn bị báo lỗi :-s bác có biết tại sao không ạ

ERR! listen Error: parseAndCheckLogin got status code: 404. Bailing out of trying to parse response.
ERR! listen at /Users/tran.duc.trung/Documents/chatbot/node_modules/facebook-chat-api/utils.js:1044:15
ERR! listen at tryCatcher (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/util.js:16:23)
ERR! listen at Function.Promise.attempt.Promise.try (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/method.js:39:29)
ERR! listen at /Users/tran.duc.trung/Documents/chatbot/node_modules/facebook-chat-api/utils.js:991:24
ERR! listen at tryCatcher (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/util.js:16:23)
ERR! listen at Promise._settlePromiseFromHandler (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:547:31)
ERR! listen at Promise._settlePromise (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:604:18)
ERR! listen at Promise._settlePromise0 (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:649:10)
ERR! listen at Promise._settlePromises (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:729:18)
ERR! listen at Promise._fulfill (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:673:18)
ERR! listen at Promise._resolveCallback (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:466:57)
ERR! listen at Promise._settlePromiseFromHandler (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:559:17)
ERR! listen at Promise._settlePromise (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:604:18)
ERR! listen at Promise._settlePromise0 (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:649:10)
ERR! listen at Promise._settlePromises (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:729:18)
ERR! listen at Promise._fulfill (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:673:18)
ERR! listen Error: parseAndCheckLogin got status code: 404. Bailing out of trying to parse response.
ERR! listen at /Users/tran.duc.trung/Documents/chatbot/node_modules/facebook-chat-api/utils.js:1044:15
ERR! listen at tryCatcher (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/util.js:16:23)
ERR! listen at Function.Promise.attempt.Promise.try (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/method.js:39:29)
ERR! listen at /Users/tran.duc.trung/Documents/chatbot/node_modules/facebook-chat-api/utils.js:991:24
ERR! listen at tryCatcher (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/util.js:16:23)
ERR! listen at Promise._settlePromiseFromHandler (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:547:31)
ERR! listen at Promise._settlePromise (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:604:18)
ERR! listen at Promise._settlePromise0 (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:649:10)
ERR! listen at Promise._settlePromises (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:729:18)
ERR! listen at Promise._fulfill (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:673:18)
ERR! listen at Promise._resolveCallback (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:466:57)
ERR! listen at Promise._settlePromiseFromHandler (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:559:17)
ERR! listen at Promise._settlePromise (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:604:18)
ERR! listen at Promise._settlePromise0 (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:649:10)
ERR! listen at Promise._settlePromises (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:729:18)
ERR! listen at Promise._fulfill (/Users/tran.duc.trung/Documents/chatbot/node_modules/bluebird/js/release/promise.js:673:18)

@CongTuHaoHoa
Copy link

@thangphamnd123 bác cho em xem code được k. Liên lạc em facebook nhé https://www.facebook.com/ngoc.thanh.meomeo

@thangphamnd123
Copy link

Mình login ok rồi, tks bác @CongTuHaoHoa đã hỗ trợ nhé. Còn bác bên trên @trungtd-1561 chắc dùng sample này để thử đúng ko
const login = require("facebook-chat-api");

// Create simple echo bot
login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
if(err) return console.error(err);

api.listen((err, message) => {
    api.sendMessage(message.body, message.threadID);
});

});

Bác thử lại bằng sample này nhé

const fs = require("fs");
const login = require("facebook-chat-api");

// Simple echo bot. It will repeat everything that you say.
// Will stop when you say '/stop'
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
if(err) return console.error(err);

api.setOptions({listenEvents: true});

var stopListening = api.listen((err, event) => {
    if(err) return console.error(err);

    api.markAsRead(event.threadID, (err) => {
        if(err) console.error(err);
    });

    switch(event.type) {
        case "message":
            if(event.body === '/stop') {
                api.sendMessage("Goodbye…", event.threadID);
                return stopListening();
            }
            api.sendMessage("TEST BOT: " + event.body, event.threadID);
            break;
        case "event":
            console.log(event);
            break;
    }
});

});

@trungtd-1561
Copy link

@thangphamnd123 mình có thử cách trên rồi nhưng vẫn bị lỗi, phải thay method listen bằng listenMqtt rồi thêm option userAgent thì lại chạy ngon :))

@thangphamnd123
Copy link

à đúng rồi, listen ko support nữa, phải thay bằng listenMqtt

@TheSohaibAhmed
Copy link

TheSohaibAhmed commented Apr 15, 2021

Here's a solution that worked for me, based on looking through the package and advice on assorted threads. I'm relatively new to coding in general, so I'll be super detailed in case someone benefits from it or can tell me if I'm off. I did the following:

P.S. I think this may have been said already in this thread, but doesn't hurt to consolidate.

1. Backend setup:

  • Installed express & fs - turns out that this is not necessary for basic setup. My bad.
  • npm install facebook-chat-api (wasn't sure what "bleeding edge" specifically implied)

ERR: { error: 'Wrong username/password.' }

2. Solution: Credential Workaround: Like someone else mentioned it earlier, you can get the credentials from your facebook page. Here are the steps I took:

  • Install puppeter chrome extension (google this)
  • Log into facebook.com (not messenger.com) (this avoids {
    error: 'Error retrieving userID. This can be caused by a lot of things, incling getting blocked by Facebook for logging in from an unknown location. Try lging in with a browser to verify.'
    })
  • Use puppeteer to get the retreive cookies in JSON format: save in backend directory as (appstate.json)
  • Go to appstate.json, and for each object (which represents a cookie), change the "name" key, to "key"

3. Avoiding potential error causes: Changing "options"

  • Change user agent: Not sure why I needed to do this, as I didn't run into any issue without it, but I did it anyway.
  • Listen to events: I'm assume that I wouldn't have been able to this without this option, so yeah
  • Listen to your own events: I used this as a way to read through my own message that I sent myself ( haven't tested this yet though)

Code:
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, selfListen: true, };


ERR! listen Error: parseAndCheckLogin got status code: 404. Bailing out of trying to parse response.

4. Solution: Remove deprecated listen method

  • This error is caused by api.listen (as the error message says) -- which is apparently deprecated. Replace api.listen with api.listenMqtt instead.
    Avoiding potential problems that could be caused by puppeteer - I'm assuming it's not necessary, as things worked just fine without it, but just in case.

5. Avoiding problems caused by future facebook updates (maybe - I'm just speculating)

  • Even though we already have appstate.js, use api.getAppState(), to get Facebook's cookies.
  • Save cookies in another json file, or overrite prev. one (I named it fbCookies.json)
  • Use the new file instead of the one you got from puppeteer - no changes required to the file.

**FULL CODE: **

const fs = require("fs");
const login = require("facebook-chat-api");
// New options

let 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, selfListen: true, };
//Nothing new
let credentials = { appState: JSON.parse(fs.readFileSync("fbCookies.json", "utf8")), };

// Used to update appState.json to FB's version
let fbCookiesStored = false;
login(
credentials,
options,
(err, api) => {
if (err) return console.error(err);
// Instead of api.listen -- that's deprecated.
api.listenMqtt((err, message) => {
if (err) {
console.log("SOHAIB: Error is in API LISTEN");
console.log(err);
} else {
//Update facebook cookies, and save in json file.
if (!fbCookiesStored) { fs.writeFileSync("fbCookies.json", JSON.stringify(api.getAppState())); fbCookiesStored = true; }
if (message.type == "message") { console.log("New message received"); console.log(message); api.getChatHistory() api.sendMessage( "I'll back to you shortly thanks.", message.threadID, (err, messageInfo) => { if (err) return console.error(err); console.log(messageInfo); } );
} else if (message.type == "event") { console.log("Event received"); console.log(message); }
} }); } );

@trgkyle
Copy link

trgkyle commented Apr 16, 2021

à đúng rồi, listen ko support nữa, phải thay bằng listenMqtt

Hiện tại mình thấy khi mình để listen một hồi thì nó không listen nữa như bị diss ra có cách nào khắc phục không các bác

@trangcongloc
Copy link

After successful login i got this error when listening, how can i fix this?

info login Logged in
info login Request to reconnect
info login Done logging in.
ERR! getSeqId TypeError: Cannot read property 'successful_results' of undefined
ERR! getSeqId     at /home/leviathan/bot/node_modules/facebook-chat-api/src/listenMqtt.js:532:41
ERR! getSeqId     at tryCatcher (/home/leviathan/bot/node_modules/bluebird/js/release/util.js:16:23)
ERR! getSeqId     at Promise._settlePromiseFromHandler (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:547:31)
ERR! getSeqId     at Promise._settlePromise (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:604:18)
ERR! getSeqId     at Promise._settlePromise0 (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:649:10)
ERR! getSeqId     at Promise._settlePromises (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:729:18)
ERR! getSeqId     at Promise._fulfill (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:673:18)
ERR! getSeqId     at Promise._resolveCallback (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:489:14)ERR! getSeqId     at Promise._settlePromiseFromHandler (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:559:17)
ERR! getSeqId     at Promise._settlePromise (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:604:18)
ERR! getSeqId     at Promise._settlePromise0 (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:649:10)
ERR! getSeqId     at Promise._settlePromises (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:729:18)
ERR! getSeqId     at Promise._fulfill (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:673:18)
ERR! getSeqId     at Promise._resolveCallback (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:466:57)ERR! getSeqId     at Promise._settlePromiseFromHandler (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:559:17)
ERR! getSeqId     at Promise._settlePromise (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:604:18)
ERR! getSeqId  TypeError: Cannot read property 'successful_results' of undefined
ERR! getSeqId     at /home/leviathan/bot/node_modules/facebook-chat-api/src/listenMqtt.js:532:41
ERR! getSeqId     at tryCatcher (/home/leviathan/bot/node_modules/bluebird/js/release/util.js:16:23)
ERR! getSeqId     at Promise._settlePromiseFromHandler (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:547:31)
ERR! getSeqId     at Promise._settlePromise (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:604:18)
ERR! getSeqId     at Promise._settlePromise0 (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:649:10)
ERR! getSeqId     at Promise._settlePromises (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:729:18)
ERR! getSeqId     at Promise._fulfill (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:673:18)
ERR! getSeqId     at Promise._resolveCallback (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:489:14)ERR! getSeqId     at Promise._settlePromiseFromHandler (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:559:17)
ERR! getSeqId     at Promise._settlePromise (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:604:18)
ERR! getSeqId     at Promise._settlePromise0 (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:649:10)
ERR! getSeqId     at Promise._settlePromises (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:729:18)
ERR! getSeqId     at Promise._fulfill (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:673:18)
ERR! getSeqId     at Promise._resolveCallback (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:466:57)ERR! getSeqId     at Promise._settlePromiseFromHandler (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:559:17)
ERR! getSeqId     at Promise._settlePromise (/home/leviathan/bot/node_modules/bluebird/js/release/promise.js:604:18) 
// code
const fs = require("fs");
const login = require("facebook-chat-api");

let options = {
    userAgent:
        "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36",
    listenEvents: true,
};

let credentials = {
    appState: JSON.parse(fs.readFileSync("fbCookies.json", "utf8")),
};

login(credentials, options, (_err, api) => {
    api.listenMqtt((_err, message) => {
        if (!_err) {
            //code
        }
    });
});

@CongTuHaoHoa
Copy link

@trangcongloc I think you should set the options after successfully log-in. Or just not to set the userAgent. Worked for me.

@shellmage
Copy link

a script using puppeteer to generate appstate.json getAppstate.js

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests