【问题标题】:Use twitter api to send direct messages using python使用 twitter api 使用 python 发送直接消息
【发布时间】:2020-05-01 09:16:32
【问题描述】:

我正在开发一个 python 脚本,以使用 python 向 twitter 上的任何人发送直接消息。为此,我正在使用 twitter api,但我不知道该怎么做。如果有人知道任何方法,请帮助我。

【问题讨论】:

    标签: python python-3.x twitter bots twitter-oauth


    【解决方案1】:

    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)
    

    【讨论】:

    • 使用twitter api发送消息需要多少钱?
    • 不花钱
    猜你喜欢
    • 2012-02-09
    • 2020-07-14
    • 1970-01-01
    • 2020-09-10
    • 1970-01-01
    • 2011-05-08
    • 2015-02-23
    • 2010-12-12
    • 1970-01-01
    相关资源
    最近更新 更多