Twython-获取最新直接消息

时间:2018-07-13 14:54:15

标签: python python-2.7 api twython

我需要从任何用户那里获取最新的直接消息。

我已经尝试过的是:

#importing twython and creating session.....
#api is the sessions name

results = api.cursor(api.get_direct_messages)

但是api每15分钟只允许15个请求,而get_direct_messages使用所有请求...所以我只能做一次api.get_direct_messages ...

那么有什么方法可以只从任何用户那里获取最新/最新的直接消息吗? (而不是一次使用全部15个请求)?


编辑/解决方案: 事实证明,此问题没有真正的解决方案,因为要获取最新消息,您必须通过我不想使用的 get_direct_messages()来查找其ID。

2 个答案:

答案 0 :(得分:1)

再看一下twythons,git使用以下代码显示this page

get_list = twitter.get_direct_messages()
#Returns All Twitter DM information which is a lot in a list format
dm_dict = get_list[0] #Show latest message
#You can cycle through all the numbers and it will return the text and the Sender id of each
print dm_dict['text']
print dm_dict['sender']['id']

我的一些测试表明,尽管有15分钟的限制,但该操作仍在重复进行。我设法每分钟退回第n个DM,共10分钟

答案 1 :(得分:0)

Twitters API指出get_direct_messages返回多个DM,但具有message id参数的get_direct_message()返回单个消息

相关问题