fbchat-dev / fbchat

Facebook Chat (Messenger) for Python
https://fbchat.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.19k stars 412 forks source link

json loads error when get "like" notify #25

Closed blcc closed 7 years ago

blcc commented 8 years ago

When fbchat start listen() and a like notification has push in, fbchat would receive a very long json string. It told you are "liked". However there are some problems in the json string, and cause json.load() error. It contains double quote in json value in 2 element. One is the "__html", which contains html code. Another one is the "tracking" element, which contains another json code.

I have no idea how to fix it.

Regards

blcc commented 8 years ago

I think life will be easier if change util.py:

def getjson(text): return json.loads(re.sub(r"for.(.;.;._).*;", '', text.encode('utf-8').decode("unicode-escape"), 1)) to

def get_json(text): return json.loads(re.sub(r"^[^{]*", '', text, 1))