I have been having problems with the MyStreamListener from tweepy, in where I am unable to fetch tweets from private accounts I follow. I know these tweets can be accessed with the API, because I can fetch them with api.user_timeline. Is there any way to be able to stream my whole timeline? Could I just continuously fetch my timeline in a while loop? Thank you for any help!
import tweepy
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
webhooklink = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
print('starting to monitor!')
class MyStreamListener(tweepy.StreamListener):
def on_status(self, status):
print(status.text)
if __name__ == '__main__':
myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth=api.auth, listener=myStreamListener)
myStream.filter(
follow='25073877', is_async=True)
Related
Anyone have any idea what could be causing the error? All my keys and tokens should be correct. I made sure to double check them. I followed the steps on how to set up the stream pretty arcuately I thought.
import time
import tweepy
import praw
#Variables that contains the credentials to access Twitter API and REDDIT
USERNAME = ""
PASSWORD = "!"
CLIENT_ID = ''
CLIENT_SECRET = ''
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, consumer_key)
api = tweepy.API(auth, wait_on_rate_limit=True)
class MyStreamListener(tweepy.Stream):
def on_status(self, status):
print("ID: {}".format(status.id))
print(status.full_text)
def streamtweets():
myStreamListener = MyStreamListener(consumer_key, consumer_secret,access_token, consumer_key)
myStream = tweepy.Stream(consumer_key, consumer_secret,access_token, consumer_key)
myStream.filter(follow = [''])
streamtweets()
You're passing your consumer_key as the access token secret.
I have been following a tutorial directly, as well as cross referencing with tweepy documentation and my code is still not authorizing to Twitters' API. I have quadruple checked my key, secrets, and tokens. I've even changed the which variables go where. Anytime I try to use the authentication methods found in the #graveyard it tells me the authentication failed. Where am I going wrong?
import tweepy
import time
consumer_key = 'xxx'
consumer_secret = 'xxx'
#bearertoken = "xxx"
access_token = 'xxx'
access_token_secret = 'xxx'
#authenticate to twitter
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
#create api object
api = tweepy.API(auth, wait_on_rate_limit=True)
##create tweet
#api.update_status('test run good')
#GRAVEYARD
#if api.verify_credentials():
# print("Success")
#else:
# print("authentication failed")
#try:
# api.verify_credentials()
# print("authentication ok")
#except:
# print("authentication failed")
Im trying to stream specific user's tweets and return them as a variable for an event based trigger afterwards. I am using the following code, but it does not seem to return any tweets for me.
I am interested in their tweets only and not retweets and want to skip tweets not posted by the specified user.
Any idea where I am going wrong:
import tweepy
#API login for Twitter
consumer_key= CONSUMER_KEY
consumer_secret= CONSUMER_SECRET
access_key= ACCESS_TOKEN
access_secret= ACCESS_TOKEN_SECRET
class StreamListener(tweepy.StreamListener):
def on_status(self, status):
if status.user.id_str != '111111111':
return
tweet = status.text
return tweet
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
# initialize stream
streamListener = StreamListener()
stream = tweepy.Stream(auth=api.auth, listener=streamListener)
stream.filter(follow=['111111111'])
print(tweet)
here is the code to stream specific user's tweets:
import tweepy
import sys
#API login for Twitter
consumer_key= CONSUMER_KEY
consumer_secret= CONSUMER_SECRET
access_key= ACCESS_TOKEN
access_secret= ACCESS_TOKEN_SECRET
# StreamListener class inherits from tweepy.StreamListener and overrides on_status/on_error methods.
class StreamListener(tweepy.StreamListener):
def on_status(self, status):
if status.user.id_str != '11111111':
return
text = status.text
print(text)
def on_error(self, status_code):
print("Encountered streaming error (", status_code, ")")
sys.exit()
if __name__ == "__main__":
# complete authorization and initialize API endpoint
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
# initialize stream
streamListener = StreamListener()
stream = tweepy.Stream(auth=api.auth, listener=streamListener,tweet_mode='extended')
stream.filter(follow=['11111111'])
I am in the processing of creating a bot that reads all mentions in userstream Twitter timeline and reply accordingly, however I cannot seem to get the users details who posted the mention in order to reply back, all I receive is the mention status/text.
I am using Python and Tweepy API to achieve this:
import tweepy
from tweepy import Stream
consumer_key = '********'
consumer_secret = '********'
access_token = '***********'
access_secret = '*********'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
class MyStreamListener (tweepy.StreamListener):
def on_status(self, status):
print(status.text)
def on_error(self, status):
print(status)
def on_direct_message(self, status):
print(status)
twitterStream = Stream(auth, MyStreamListener())
userStream = twitterStream.userstream()
Any help would be greatly appreciated
It needed
print(status.author.screen_name)
i want to stream my own twitter timeline with python and tweepy and use code in below but it just print me some numbers and i dosent print my timeline twitts. Can you help me?
import tweepy
from tweepy import Stream
from tweepy.streaming import StreamListener
consumer_key = 'abc'
consumer_secret = 'abc'
access_token = 'abc'
access_secret = 'abc'
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
class listener(StreamListener):
def on_data(self, data):
print (data)
return True
def on_error(self, status):
print (status)
twitterStream = Stream(auth, listener())
twitterStream.userstream(encoding='utf8')
If you take a look at the documentation it says:
The on_data method of Tweepy’s StreamListener conveniently passes data from statuses to the on_status method.
The numbers you are seeing are the object IDs of the Tweets. You will need to do something like:
def on_status(self, status):
print(status.text)