发送Facebook消息

2024-05-03 05:54:13 发布

您现在位置:Python中文网/ 问答频道 /正文

只是想用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))

错误:

Traceback (most recent call last):

File "main.py", line 13, in

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

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


Tags: textfromimportclientsendidtypemsg
2条回答

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

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

其中message对象是传入send的第一个参数,后跟thread\u id和thread\u type。你知道吗

几年前我花了一些时间探索这个模块。你知道吗

快速回顾github示例,线程id应该是一个数字。你知道吗

这样的变化

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

client.send(Message(text=msg), thread_id=uid, thread_type=ThreadType.USER)

在你的代码里。因为你的uid也是你要发送的朋友的。你知道吗

相关问题 更多 >