首页 > 解决方案 > 发送 Facebook 消息

问题描述

只是想用 python 发送一条 Facebook 消息。

代码:

import fbchat

from fbchat import Client

from fbchat.models import *

client = Client("my_username", "my_password")

#help(fb.Client.send)

#client.send(text="This is a test", thread_id="christopher.batey", thread_type=ThreadType.USER)

name = "christopher.batey"

friends = client.searchForUsers(name)

friend = friends[0]

uid = friend.uid

msg = "This is a test"

print(help(client.send))

client.send(Message(text=msg, thread_id="christopher.batey", thread_type=ThreadType.USER))

错误:

回溯(最近一次通话最后):

文件“main.py”,第 13 行,在

client.send(Message(text=msg, thread_id="christopher.batey", thread_type=ThreadType.USER))

TypeError: init () got an unexpected keyword argument 'thread_id'

标签: pythonpython-3.xfacebook

解决方案


我不熟悉 API,但从文档来看,正确的调用应该是:

client.send(Message(text=msg), thread_id="christopher.batey", thread_type=ThreadType.USER)

其中消息对象是传递给 send 的第一个参数,然后是 thread_id 和 thread_type。


推荐阅读