使用 Twitter api 使用 python 发送直接消息

Use twitter api to send direct messages using python

我正在开发一个 python 脚本来使用 python.For 向 Twitter 上的任何人发送直接消息 我正在使用 Twitter api 但我不知道如何 that.If任何人知道任何方法请帮助我。

TwitterAPI

from TwitterAPI import TwitterAPI
import json

api = TwitterAPI(<consumer key>, 
                 <consumer secret>,
                 <access token key>,
                 <access token secret>)

user_id = <user id of the recipient>
message_text = <the DM text>

event = {
    "event": {
        "type": "message_create",
        "message_create": {
            "target": {
                "recipient_id": user_id
            },
            "message_data": {
                "text": message_text
            }
        }
    }
}

r = api.request('direct_messages/events/new', json.dumps(event))
print('SUCCESS' if r.status_code == 200 else 'PROBLEM: ' + r.text)