python - 发送 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'
解决方案
我不熟悉 API,但从文档来看,正确的调用应该是:
client.send(Message(text=msg), thread_id="christopher.batey", thread_type=ThreadType.USER)
其中消息对象是传递给 send 的第一个参数,然后是 thread_id 和 thread_type。
推荐阅读
- postgis - 如何解决不同 Lat, Long 对的 OSM ID 相同的问题?
- r - 如何将gsub结果分成R中的两个列表?
- .net - .Net Core 上的 WsHttpBinding
- javascript - InnerHTML 改函数 JAVASCRIPT/JQUERY
- c++ - 如何在 VS - Code (Windows) 中同时编译和运行我的 c++ 代码
- reporting-services - SSRS:以预期格式对齐输出
- html - 使用网格布局 + 引导程序 + 表格溢出时保持页眉/页脚位置
- python - 在大型 CSV 文件中查找 #ROWS
- html - 工具提示框向上而不是底部显示
- python - Numpy:从第(m)维中删除最后(n)个元素