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

Error in getThreadList() #10

Closed xcorat closed 8 years ago

xcorat commented 9 years ago

getThreadList() gives me an error in python 3.4. It was fixed by changing

https://github.com/carpedm20/fbchat/blob/master/fbchat/client.py#L224

 t = Thread(thread)

to

 t = Thread(**thread)

(I can fork and fix it if needed, unless you guys have already fixed it)

PidgeyL commented 8 years ago

I forked this, fixed this, and will create a pull request tonight, after taking a look at some other bugs

carpedm20 commented 8 years ago

@PidgeyL Thx!

carpedm20 commented 8 years ago

12 Solved

wannaphong commented 8 years ago

how to use getThreadList() ?

PidgeyL commented 8 years ago

from the code: def getThreadList(self, start, end=None):, I'm assuming it's calculating back in time, where start is either 0 (the last message) or a number of messages to skip, and end is the x'th message

wannaphong commented 8 years ago

Error code

import fbchat
client = fbchat.Client("id", "pass")
print(client.getThreadList(0))

Traceback (most recent call last): File "", line 1, in File "C:\py34\lib\site-packages\fbchat\client.py", line 221, in getThreadList j = get_json(r.text) File "C:\py34\lib\site-packages\fbchat\utils.py", line 18, in getjson return json.loads(re.sub(r"for.(.;.;._).*;", '', text.encode('utf-8').dec ode("unicode-escape"), 1)) File "C:\py34\lib\jsoninit.py", line 318, in loads return _default_decoder.decode(s) File "C:\py34\lib\json\decoder.py", line 343, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\py34\lib\json\decoder.py", line 359, in raw_decode obj, end = self.scan_once(s, idx) ValueError: Expecting ',' delimiter: line 1 column 2567 (char 2566)

PidgeyL commented 8 years ago

That's very odd. Doesn't seem like something I changed. Can you print the json from the getTrheadList?

wannaphong commented 8 years ago

No, I can't. :sob:

PidgeyL commented 8 years ago

Sure you can. when you download this project, add the following line to fbchat/client.py, on line 221:

print(j)

Then, run sudo pip uninstall fbchat (or pip3 if you're using python3) to uninstall the current fbchat Then, run 'sudo python setup.py install' (or python3) to install your modified version Then run the script again (or your code in the interpreter) to get the output of the json

I don't know if there is any personal data in the json file, I don't know it by heart. If you're using a dummy facebook account, it doesn't matter, but if you don't, perhaps have a look at the output, and replace any ouput that looks personal by fake output, but keep the same format (numbers vs letters, length, etc)

wannaphong commented 8 years ago
import fbchat
client = fbchat.Client("id", "pass")
print(client.getThreadList(0))
,"thread_fbid":null,"time":0000004752987},{"other_user_fbid":"000000395885","
thread_fbid":null,"time":00000098306},{"other_user_fbid":"00000088685","th
read_fbid":null,"time":000000001561}],"payload_source":"server_fetch_threadlist
_info"},"bootloadable":{},"ixData":{},"lid":"6224703000000533"}
wannaphong commented 8 years ago

Or, as Thai lang . Facebook used to encode non-utf8.

PidgeyL commented 8 years ago

Sounds legit. I'll take a look when I have some time. When you look for "snippet" in the text, what does that look like? Text, Null, ... ?

wannaphong commented 8 years ago

feom test https://github.com/wannaphongcom/fbchat/commit/9d4d44372f0045175b6254b9894cfddeb8192701

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\py34\lib\site-packages\fbchat\client.py", line 235, in getThreadList
    j = get_json(r.text)
  File "C:\py34\lib\site-packages\fbchat\utils.py", line 18, in get_json
    return json.loads(re.sub(r"for.*(.*;.*;.*).*;", '', text.encode('utf-8').dec
ode("unicode-escape"), 1))
  File "C:\py34\lib\json\__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "C:\py34\lib\json\decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\py34\lib\json\decoder.py", line 359, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting ',' delimiter: line 1 column 17182 (char 17181)
PidgeyL commented 8 years ago

yeah, I understand that, but I would need to know the format of the data, to see how to parse it properly :)

wannaphong commented 8 years ago
{"fbid":1000ss8,"gender":2,"href":"https:\/\/www.facebook.com\/profile.php?id=","id":"fbid:friends","image_src":"https:\/\/f","big_image_src":"https:\/\/","name":"\u0e40\u0e0a\u0e19 ",
"short_name":"\u0e40","employee":false,"is_employee_away":false,"typ
e":"user","vanity":"","is_friend":true,"social_snippets":[],"is_messenger_user":
true}
PidgeyL commented 8 years ago

I think I see the issue. I wouldn't be surprised if regex couldn't handle unicode like that. Could you open a new issue with this information?

wannaphong commented 8 years ago

The result of getThreadList() Of you?

PidgeyL commented 8 years ago

Well this issue is closed (and a different issue), so could you open a new ticket which includes the info you put here, so we can work on it?