【发布时间】:2021-01-17 20:28:53
【问题描述】:
我想使用 Tweepy 库和 Twitter 的 API 在 Python 中发送带有快速回复选项的直接消息。 Tweepy 文档说我可以使用以下代码发送带有快速回复选项的 DM:
API.send_direct_message(recipient_id, text[, quick_reply_type][, attachment_type][, attachment_media_id])
我尝试通过使用 Python 创建自己的选项来实现它,这就是我实现它的方式:
import tweepy
import time
#login credentials need to be filled here
auth = tweepy.OAuthHandler('','')
auth.set_access_token('', '')
api = tweepy.API(auth)
user = api.get_user("user's name")
options = [
{
"label": "I'm good",
"description": "It means you're doing good",
"metadata": "external_id_1"
},
{
"label": "Not so good",
"description": "It means you're not doing good",
"metadata": "external_id_2"
}
]
direct_message = api.send_direct_message(user.id, "Hey Man! How's it going?", quick_reply_type=options)
我最终得到了这个错误:
tweepy.error.TweepError: [{'code': 214, 'message': 'event.message_create.message_data.quick_reply: Unknown quick_reply type '}]
我什至尝试将这些选项放入 Python 对象中并使其可序列化为 JSON,但它最终仍然给出了相同的错误。我该怎么办?
【问题讨论】:
标签: python twitter chatbot tweepy