无法在python上使用fbchat发送消息

时间:2017-10-30 23:18:15

标签: python python-3.x google-python-api

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()

上面的代码示例是我从在线教程获得的,该程序能够登录到Facebook messenger并告诉我我的用户ID。然后我添加了一个client.send,看看它是否真的使用facebook messenger向我的一个联系人发送消息,但后来我得到了IDLE。任何人都可以为这个问题提供解决方案吗?

    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

1 个答案:

答案 0 :(得分:1)

您可能需要试试这个。我认为你的thread_id是错误的。

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