【问题标题】:Cannot send messages using fbchat on python无法在 python 上使用 fbchat 发送消息
【发布时间】:2017-10-30 23:18:14
【问题描述】:
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

【问题讨论】:

  • 将thread_id值改为client.uid

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


【解决方案1】:

您可能需要尝试一下。我认为你的 thread_id 是错误的。

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

【讨论】:

  • 所以如果我想向另一个人发送消息,我会将 client.uid 更改为客户 ID??
  • @RS 没错。该程序将向您自己发送一条消息:D。除非你想要自言自语?
猜你喜欢
  • 1970-01-01
  • 2020-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多