【问题标题】:Updated Twitter Direct Messages API with Tweepy使用 Tweepy 更新了 Twitter 直接消息 API
【发布时间】:2019-02-21 22:46:03
【问题描述】:

Twitter 今天更新了他们的消息 API (https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-event),我通过 Tweepy 编写的与发送直接消息相关的所有 Python 代码都已停止工作,我似乎无法让它工作。这是我现在的代码:

direct_message = api.send_direct_message(user=username, text=message_text)

但是,我从 Twitter 收到以下错误响应:

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

我对如何使用 Tweepy 实现新的 API 更改感到困惑。直到今天它工作得非常好,但现在它不能工作......我 100% 确定用户已通过身份验证并且有权发送消息,但我仍然收到错误消息。

【问题讨论】:

标签: python twitter tweepy


【解决方案1】:

更新 Tweepy。在 twitter 应用程序中检查它的权限。撤销密钥。 现在试试这个简单的代码。

 def direct_message(api):
 logger.info("Start send mensage")

 for dm in tweepy.Cursor(api.followers_ids).items(10):
       #edit the msg parameter     
      api.send_direct_message(dm, 'Watching our new indie game trailer from my creator @AGTAStudios on Youtube : https://youtu.be/qGC-0toodmA')
      logger.info("msg send") 

def main():
    api = create_api()
    direct_message(api)


if __name__ == "__main__":
    main()

如果不起作用,请回复错误。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 2017-05-22
    • 1970-01-01
    • 2020-05-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-22
    相关资源
    最近更新 更多