I'm trying to get the text from tweets about a hashtag that can be input and then store them in a json file so that I can do stuff like count how many times a word is used in all the tweets.
I tried to cast tweet as a string with str(tweet) but that just gave a different error and I mostly just did it as a guess.
api = tweepy.API(auth)
def jsontweetdump(tweet):
with open('tweet.json', 'w') as outfile:
json.dump(tweet, outfile)
hashtag = input()
for tweet in tweepy.Cursor(api.search, hashtag, count=10).items():
jsontweetdump(tweet)
I expected that this would store data from ten tweets based on the hashtag i put in in a json file but I'm getting these error messages.
Traceback (most recent call last):
File "main.py", line 22, in <module>
jsontweetdump(tweet)
File "main.py", line 17, in jsontweetdump
json.dump(tweet, outfile)
File "/usr/local/lib/python3.6/json/__init__.py", line 179, in dump
for chunk in iterable:
File "/usr/local/lib/python3.6/json/encoder.py", line437, in _iterencode
o = _default(o)
File "/usr/local/lib/python3.6/json/encoder.py", line180, in default
o.__class__.__name__)
TypeError: Object of type 'Status' is not JSON serializable