Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Twython-获取最新的直接消息_Python_Python 2.7_Api_Twython - Fatal编程技术网

Python Twython-获取最新的直接消息

Python Twython-获取最新的直接消息,python,python-2.7,api,twython,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_消息使用所有请求。。。所以我可以做api。只获取一次直接消息 那么,有没有办法只从任何用户那里获取最新/最新的直接消息?(而不是同时使用所有1

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

我已经尝试过的是:

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

results = api.cursor(api.get_direct_messages)
但是api每15分钟只允许15个请求,get_direct_消息使用所有请求。。。所以我可以做
api。只获取一次直接消息

那么,有没有办法只从任何用户那里获取最新/最新的直接消息?(而不是同时使用所有15个请求)


编辑/解决方案:
事实证明,这个问题没有真正的解决方案,因为为了获取最新消息,您必须通过我不想使用的get\u direct\u messages()找到它的id。

Twitters API声明get\u direct\u消息返回多个DM,但get\u direct\u messages()使用message id参数返回一条消息

使用以下代码查看twythons git显示:

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分钟。我已经设法在10分钟内每分钟返回第n个DM,但我想得到最新的dms,但无法得到id,或者有没有办法得到我得到的最新dms?你可以使用get_direct_消息并选择最大的id来返回最新消息。这似乎不能回答OP的问题,因为它不处理“15分钟”方面。我使用twython Git示例添加了一个新答案,以返回最新消息