pythonpython-2.7twython

Twython - get the latest direct message


I need to get the latest direct message from any user.

What I already tried is:

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

results = api.cursor(api.get_direct_messages)

but the api only allows 15 requests per 15 minutes and get_direct_messages uses all of them... So I can do api.get_direct_messages only once...

So is there a way to get only the latest/newest direct message from any user? (And not using all of the 15 requests at once)?


Edit/Solution: It turned out that there is no real solution to this problem because in order to get the latest message you have to find out it's id via get_direct_messages() which I don't want to use.


Solution

  • A little more looking at twythons git shows this page using the following code :

    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']
    

    some testing on my end shows this working repeatedly dspite the 15 minute limit. I have managed to return the n'th DM every minute for 10 minites