1
from fbchat import Client
from fbchat.models import *

client = Client('<username>', '<password>')

print('Own id: {}'.format(client.uid))

client.send(Message(text='Hi me!'), thread_id='clientname', thread_type=ThreadType.USER)

client.logout()

The code sample above is what I got from a tutorial online, the program is able to login to Facebook messenger and tell me my user id. Then I added in a client.send to see if it actually sends a message using facebook messenger to one of my contacts but then i get this in IDLE. Can anybody provide solutions for this issue?

    Traceback (most recent call last):
  File "C:/Users/User/Desktop/Python/fbchat trial.py", line 10, in <module>
    client.send(Message(text='Hi me!'), thread_id='User', thread_type=ThreadType.USER)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\fbchat\client.py", line 955, in send
    return self._doSendRequest(data)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\fbchat\client.py", line 923, in _doSendRequest
    j = self._post(self.req_url.SEND, data, fix_request=True, as_json=True)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\fbchat\client.py", line 128, in _post
    raise e
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\fbchat\client.py", line 124, in _post
    return check_request(r, as_json=as_json)
  File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\fbchat\utils.py", line 193, in check_request
    raise FBchatFacebookError('Error when sending request: Got {} response'.format(r.status_code), request_status_code=r.status_code)
fbchat.models.FBchatFacebookError: Error when sending request: Got 500 response
R S
  • 33
  • 1
  • 6

1 Answers1

3

You may need to try this. I think your thread_id is wrong.

client.send(Message(text='Hi me!'), thread_id=client.uid, thread_type=ThreadType.USER)
hahahakebab
  • 328
  • 7
  • 22
  • so if i want to send a message to another person i would change client.uid to the clients id?? – R S Oct 30 '17 at 23:32
  • 2
    @RS That's correct. This program will send a message to yourself :D. Unless talking to yourself is what you want? – hahahakebab Oct 30 '17 at 23:32