How do i access direct messages with python?


#1

Very new to the twitter api. I want to make an app that, when a certain account get a new DM, will tweet the DM, then delete it. I know how to code in python, but am having trouble with learning the API and would love some help. So far this is my code

from twitter import *

what should our new status be?

status_update = “Testing”

these tokens are necessary for user authentication

(created within the twitter developer API pages)

consumer_key = x
consumer_secret = x
access_key = x
access_secret = x

create twitter API object

auth = OAuth(access_key, access_secret, consumer_key, consumer_secret)
twitter = Twitter(auth = auth)

post a new status

twitter API docs: https://dev.twitter.com/docs/api/1/post/statuses/update

results = twitter.statuses.update(status = status_update)
twitter.direct_messages.new(
user=“MY_USERNAME",
text=status_update)
print "Status updated.”

And it all works and complies correctly, and will in fact tweet to my account and send myself the message as a DM. That’s all i have so far… So i have the posting down, i just don’t know how to access read and delete DM’s… Any help is much appreciated as i am a new developer…