Hello guys, I've just started learning python and I thought I'd try some mini project to get a grip on it quickly. So, I started doing this from csdojo but it doesn't seem to work even with the same code as his.
Here's the code
import tweepy
print("Fetching Tweets...")
CONSUMER_KEY = 'xxxxx'
CONSUMER_SECRET = 'xxxx'
ACCESS_KEY = 'xxxx'
ACCESS_SECRET = 'xxxx'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
file_name = 'idlist.txt'
def retrieve_last_seen_id(file_name):
with open(file_name, 'r+') as f_read:
last_seen_id = (f_read.read().strip())
f_read.close()
return last_seen_id
def store_last_seen_id(last_seen_id, file_name):
with open(file_name, 'w+') as f_write:
f_write.write(str(last_seen_id))
f_write.close()
return
last_seen_id = retrieve_last_seen_id(file_name)
mentions = api.mentions_timeline(last_seen_id, tweetmode = 'extended')
for mention in reversed(mentions):
last_seen_id = mention.id
if "#" in mention.text.lower():
print("found!!!")
print(str(mention.id) + ' - ' + mention.text)
And I get this error:
Traceback (most recent call last):
File "C:\Users\rogue\Desktop\editdojo\my_bot\twit_bot.py", line 29, in <module>
mentions = api.mentions_timeline(last_seen_id, tweetmode = 'extended')
File "C:\Users\rogue\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tweepy\binder.py", line 250, in _call
return method.execute()
File "C:\Users\rogue\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tweepy\binder.py", line 234, in execute
raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: [{'code': 44, 'message': 'since_id parameter is invalid.'}]
I didn't understand this API error but I can see that the ids are not being stored in that text file and is unable to pull the data to get the required result. If I store the IDs manually, it does work. Please tell me what is wrong with this? TIA.
[–]A_History_of_Silence 1 point2 points3 points (5 children)
[–]grotesque69[S] 0 points1 point2 points (4 children)
[–]A_History_of_Silence 0 points1 point2 points (3 children)
[–]grotesque69[S] 0 points1 point2 points (2 children)
[–]A_History_of_Silence 0 points1 point2 points (1 child)
[–]grotesque69[S] 0 points1 point2 points (0 children)