I'm running the tweepy streamer using the on_data
function, and I cannot get the full tweet even is the mode is set to extended
: when I run my def on_data
passing the text
argument only, then I get the truncated tweets, and that's fine, but when I am passing full_text
, then I get the following error: KeyError: 'full_text'
. I think I a doing what I understood from the Tweepy API docs, but I am still getting errors. Can anyone help me here?
def on_data(self, data):
json_load = json.loads(data)
tweet = json_load["full_text"]
user = json_load["user"]["screen_name"]
print(user, tweet)
try:
with open("data_file.txt", 'a') as df:
df.write(tweet + "\n")
return True
except BaseException as e:
print("Error on_data %s" % str(e))
return True
# letting the user decide the subject
subj = input("please enter the hashtag to follow separated by commas: ")
stream_listener = MyStreamListener()
tweets = tweepy.Stream(auth = api.auth, listener=stream_listener, tweet_mode="extended")
tweets.filter(track=[subj], is_async=True)```