Reputation: 33
My eventual goal is to create a twitter "bot" that takes input via direct messages and alters a publically-visible webpage depending on the input. I was originally planning on doing this with public messages but that got annoying fast, and so I'm adapting my Tweepy stream to utilize DMs.
As of right now, the following code works and, when the script is running, I receive notification and process all posts made by someone that my test user is following, but no direct messages show up.
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
class CustomStreamListener(tweepy.StreamListener):
...
def on_status(self, status):
print status
...
sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
sapiuser = sapi.userstream()
https://dev.twitter.com/discussions/8081 and the links that follow (8110, 4088) make it seem like this should work (that the built-in tweepy code should be able to access it fine), assuming that I have r/w/dm privileges on the dev.twitter.com control panel, which this account does. (I changed Application Type under Settings to all three and recreated an access token that says it has these rights - did I need to do anything else) I'm going to try to deconstruct Tweepy and check my HTTP header access level right now, but any other advice will be greatly appreciated. Thanks!
Edit: https://dev.twitter.com/discussions/4088 recommended to check the HTML header "x-access-level" in any response to verify that I have DM privileges, and I do.
Upvotes: 0
Views: 1684
Reputation: 3196
The problem is that you are using the wrong method in your StreamListener
. The on_status
method is called when a new tweet is received from the stream. Instead, you'll want to create a method called on_direct_message
. Tweepy will call that method whenever a new direct message is received.
Upvotes: 2