Hello everyone, i want to use the twitter api to retrieve tweets and forward them to my IA model for classification using Streamlit for the Web application , the issue is that i could retrieve data in an independent script with tweepy but when using the same lines of code in my streamlit script and running it I get the “401 Unauthorized” error
consumerKey = '#'
consumerSecret = '#'
accessToken = '#'
accessTokenSecret = '#'
#Create the authentication object
authenticate = tweepy.OAuthHandler(consumerKey, consumerSecret)
# Set the access token and access token secret
authenticate.set_access_token(accessToken, accessTokenSecret)
# Creating the API object while passing in auth information
api = tweepy.API(authenticate, wait_on_rate_limit = True)
if st.button("Analyze"):
if Analyzer_choice == "Show Recent Tweets":
st.success("Fetching last 5 Tweets")
def Show_Recent_Tweets(raw_text):
# Extract 100 tweets from the twitter user
posts = api.user_timeline(screen_name=raw_text, count = 20, lang ="en", tweet_mode="extended")
def get_tweets():
l=[]
i=1
for tweet in posts[:5]:
l.append(tweet.full_text)
i= i+1
return l
recent_tweets=get_tweets()
return recent_tweets
recent_tweets= Show_Recent_Tweets(raw_text)
st.write(recent_tweets)
Unauthorized: 401 Unauthorized
Traceback:
File "D:\anaconda\envs\deeplearning\lib\site-packages\streamlit\scriptrunner\script_runner.py", line 443, in _run_script
exec(code, module.__dict__)
File "C:\Users\hp\Desktop\Tweet-Analyzer-master\app.py", line 331, in <module>
app()
File "C:\Users\hp\Desktop\Tweet-Analyzer-master\app.py", line 116, in app
recent_tweets= Show_Recent_Tweets(raw_text)
File "C:\Users\hp\Desktop\Tweet-Analyzer-master\app.py", line 101, in Show_Recent_Tweets
posts = api.user_timeline(screen_name=raw_text, count = 20, lang ="en", tweet_mode="extended")
File "D:\anaconda\envs\deeplearning\lib\site-packages\tweepy\api.py", line 33, in wrapper
return method(*args, **kwargs)
File "D:\anaconda\envs\deeplearning\lib\site-packages\tweepy\api.py", line 46, in wrapper
return method(*args, **kwargs)
File "D:\anaconda\envs\deeplearning\lib\site-packages\tweepy\api.py", line 571, in user_timeline
return self.request(
File "D:\anaconda\envs\deeplearning\lib\site-packages\tweepy\api.py", line 257, in request
raise Unauthorized(resp)
i’ve tried regenerating the tokens, using another app, using the bearer token instead ,synchin the clock… but the issue persist and seems to be that twitter is blocking me from using the api in streamlit only