From 637319ec2cdf849c3c85acafe077cfed6e698a3f Mon Sep 17 00:00:00 2001 From: "Bankde@hotmail.com" Date: Mon, 10 Jul 2017 00:47:09 +0700 Subject: [PATCH 1/2] add token update --- fbchat/client.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fbchat/client.py b/fbchat/client.py index 668703e..24da9c9 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -831,6 +831,13 @@ class Client(object): except (KeyError, IndexError) as e: raise Exception('Error when sending message: No message IDs could be found: {}'.format(j)) + # update JS token if receive from response + if ('jsmods' in j) and ('require' in j['jsmods']): + try: + self.payloadDefault['fb_dtsg'] = j['jsmods']['require'][3] + except (KeyError, IndexError) as e: + log.warning("Error when update fb_dtsg. Facebook might have changed protocol.") + return message_id def sendMessage(self, message, thread_id=None, thread_type=ThreadType.USER): From 2a223ec6db09234afafe8138bda5f6914e42bfbd Mon Sep 17 00:00:00 2001 From: "Bankde@hotmail.com" Date: Mon, 10 Jul 2017 10:25:23 +0700 Subject: [PATCH 2/2] fix array indexing (I don't know why fb do that) --- fbchat/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index 24da9c9..8d66971 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -834,7 +834,7 @@ class Client(object): # update JS token if receive from response if ('jsmods' in j) and ('require' in j['jsmods']): try: - self.payloadDefault['fb_dtsg'] = j['jsmods']['require'][3] + self.payloadDefault['fb_dtsg'] = j['jsmods']['require'][0][3][0] except (KeyError, IndexError) as e: log.warning("Error when update fb_dtsg. Facebook might have changed protocol.")