簡體   English   中英

Twitter API - Tweepy 庫 - send_direct_message

[英]Twitter API - Tweepy Library - send_direct_message

我是 Tweepy (v3.7.0) 的新手,我正在嘗試向我的一些關注者發送直接消息。 但是, send_direct_message(user_id/screen_name,text)函數似乎不起作用。 我發現了一些舊線程,其中提到 Twitter 的舊直接消息端點已被棄用,這導致了問題。 關於如何使用新端點向我的關注者發送直接消息的任何建議? 最新版本的 Tweepy 是否解決了這個問題?

我嘗試了以下代碼:

api.send_direct_message(follower.screen_name,"Hi @"+follower.screen_name)

檢索關注者列表:

for follower in limit_handled(tweepy.Cursor(api.followers).items()):

錯誤信息:

Error: [{'code': 34, 'message': 'Sorry, that page does not exist.'}]

您必須更改官方 tweepy api 代碼的一些代碼。

第一個變化將是api.py和第二變化將是這個binder.py

之后,您可以在代碼中執行以下方法並使用此新方法發送消息。

event = {
  "event": {
    "type": "message_create",
    "message_create": {
      "target": {
        "recipient_id": '434259741'
      },
      "message_data": {
        "text": 'This is a new test'
      }
    }
  }
}

api.send_direct_message_new(event)

如果您想了解更多關於這個問題這里就是這個問題已經討論過的鏈接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM