From 932bde4f9f8871fcae111f7d076b32e727118f59 Mon Sep 17 00:00:00 2001 From: John Westhoff Date: Thu, 29 Dec 2016 13:12:17 -0500 Subject: [PATCH 1/2] Added support for group threds in getThreadInfo --- fbchat/client.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 777de09..8b07dce 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -326,21 +326,27 @@ class Client(object): # Strip the start and parse out the returned image_id return json.loads(r._content[9:])['payload']['metadata'][0]['image_id'] - def getThreadInfo(self, userID, start, end=None): + def getThreadInfo(self, userID, start, end=None, thread_type='user'): """Get the info of one Thread :param userID: ID of the user you want the messages from :param start: the start index of a thread :param end: (optional) the last index of a thread + :param thread_type: (optional) change from 'user' for group threads """ if not end: end = start + 20 if end <= start: end = start + end data = {} - data['messages[user_ids][%s][offset]'%userID] = start - data['messages[user_ids][%s][limit]'%userID] = end - data['messages[user_ids][%s][timestamp]'%userID] = now() + if thread_type == 'user': + key = 'user_ids' + else: + key = 'thread_fbids' + + data['messages[{}][{}][offset]'.format(key, userID)] = start + data['messages[{}][{}][limit]'.format(key, userID)] = end + data['messages[{}][{}][timestamp]'.format(key, userID)] = now() r = self._post(MessagesURL, query=data) if not r.ok or len(r.text) == 0: From 8400fd1be0ac7971bd4e86f3256f4421918818b6 Mon Sep 17 00:00:00 2001 From: "Bankde@hotmail.com" Date: Wed, 18 Jan 2017 19:43:38 +0700 Subject: [PATCH 2/2] Add logout feature --- fbchat/client.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fbchat/client.py b/fbchat/client.py index 777de09..245dcf5 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -39,6 +39,7 @@ StickyURL ="https://0-edge-chat.facebook.com/pull" PingURL ="https://0-channel-proxy-06-ash2.facebook.com/active_ping" UploadURL ="https://upload.facebook.com/ajax/mercury/upload.php" UserInfoURL ="https://www.facebook.com/chat/user_info/" +LogoutURL ="https://www.facebook.com/logout.php" class Client(object): """A client for the Facebook Chat (Messenger). @@ -159,6 +160,7 @@ class Client(object): r = self._get(BaseURL) soup = bs(r.text, "lxml") self.fb_dtsg = soup.find("input", {'name':'fb_dtsg'})['value'] + self.fb_h = soup.find("input", {'name':'h'})['value'] self._setttstamp() # Set default payload self.payloadDefault['__rev'] = int(r.text.split('"revision":',1)[1].split(",",1)[0]) @@ -187,6 +189,19 @@ class Client(object): else: return False + def logout(self, timeout=30): + data = {} + data['ref'] = "mb" + data['h'] = self.fb_h + payload=self._generatePayload(data) + r = self._session.get(LogoutURL, headers=self._header, params=payload, timeout=timeout) + # reset value + self.payloadDefault={} + self._session = requests.session() + self.req_counter = 1 + self.seq = "0" + return r + def listen(self): pass