Compare commits

...

5 Commits

Author SHA1 Message Date
Mads Marquart
a0b978004c Bump version: 1.7.2 → 1.7.3 2019-07-20 17:09:03 +02:00
Mads Marquart
efc8776e70 Fix login check, close #446
Facebook changed something internally, so that the redirected url is no longer always "/home.php", but instead sometimes just "/"
2019-07-20 17:01:54 +02:00
Szczepan Wiśniowski
915f9a3782 Add heart reaction (#445) 2019-07-20 16:21:44 +02:00
Mads Marquart
e136d77ade Fix 2FA login error, closes #442, replaces #443 2019-07-20 16:00:32 +02:00
Mads Marquart
04aec15833 Fix documentation badge 2019-07-04 00:43:34 +02:00
6 changed files with 23 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.7.2
current_version = 1.7.3
commit = True
tag = True

View File

@@ -9,7 +9,7 @@ fbchat: Facebook Chat (Messenger) for Python
:target: https://pypi.python.org/pypi/fbchat
:alt: Supported python versions: 2.7, 3.4, 3.5, 3.6, 3.7 and pypy
.. image:: https://readthedocs.org/projects/fbchat/badge/?version=master
.. image:: https://readthedocs.org/projects/fbchat/badge/?version=latest
:target: https://fbchat.readthedocs.io
:alt: Documentation

View File

@@ -13,7 +13,7 @@ from ._client import Client
from ._util import log # TODO: Remove this (from examples too)
__title__ = "fbchat"
__version__ = "1.7.2"
__version__ = "1.7.3"
__description__ = "Facebook Chat (Messenger) for Python"
__copyright__ = "Copyright 2015 - 2019 by Taehoon Kim"

View File

@@ -251,7 +251,12 @@ class Client(object):
for i in range(1, max_tries + 1):
try:
state = State.login(email, password, user_agent=user_agent)
state = State.login(
email,
password,
on_2fa_callback=self.on2FACode,
user_agent=user_agent,
)
uid = state.get_user_id()
if uid is None:
raise FBchatException("Could not find user id")

View File

@@ -35,6 +35,7 @@ class EmojiSize(Enum):
class MessageReaction(Enum):
"""Used to specify a message reaction"""
HEART = ""
LOVE = "😍"
SMILE = "😆"
WOW = "😮"

View File

@@ -24,6 +24,12 @@ def session_factory(user_agent=None):
return session
def is_home(url):
parts = _util.urlparse(url)
# Check the urls `/home.php` and `/`
return "home" in parts.path or "/" == parts.path
def _2fa_helper(session, code, r):
soup = find_input_fields(r.text)
data = dict()
@@ -39,7 +45,7 @@ def _2fa_helper(session, code, r):
r = session.post(url, data=data)
if "home" in r.url:
if is_home(r.url):
return r
del data["approvals_code"]
@@ -52,7 +58,7 @@ def _2fa_helper(session, code, r):
# At this stage, we have dtsg, nh, name_action_selected, submit[Continue]
r = session.post(url, data=data)
if "home" in r.url:
if is_home(r.url):
return r
del data["name_action_selected"]
@@ -60,7 +66,7 @@ def _2fa_helper(session, code, r):
# At this stage, we have dtsg, nh, submit[Continue]
r = session.post(url, data=data)
if "home" in r.url:
if is_home(r.url):
return r
del data["submit[Continue]"]
@@ -69,7 +75,7 @@ def _2fa_helper(session, code, r):
# At this stage, we have dtsg, nh, submit[This was me]
r = session.post(url, data=data)
if "home" in r.url:
if is_home(r.url):
return r
del data["submit[This was me]"]
@@ -107,7 +113,7 @@ class State(object):
}
@classmethod
def login(cls, email, password, user_agent=None):
def login(cls, email, password, on_2fa_callback, user_agent=None):
session = session_factory(user_agent=user_agent)
soup = find_input_fields(session.get("https://m.facebook.com/").text)
@@ -131,7 +137,7 @@ class State(object):
if "save-device" in r.url:
r = session.get("https://m.facebook.com/login/save-device/cancel/")
if "home" in r.url:
if is_home(r.url):
return cls.from_session(session=session)
else:
raise _exception.FBchatUserError(
@@ -143,7 +149,7 @@ class State(object):
# Send a request to the login url, to see if we're directed to the home page
url = "https://m.facebook.com/login.php?login_attempt=1"
r = self._session.get(url, allow_redirects=False)
return "Location" in r.headers and "home" in r.headers["Location"]
return "Location" in r.headers and is_home(r.headers["Location"])
def logout(self):
logout_h = self._logout_h