Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twitter Auth isses - Colab #1

Open
Techfluent-au opened this issue Jan 26, 2023 · 0 comments
Open

Twitter Auth isses - Colab #1

Techfluent-au opened this issue Jan 26, 2023 · 0 comments

Comments

@Techfluent-au
Copy link

`## Add Twitter Sentiment Analysis
import tweepy
from textblob import TextBlob

Authenticate with Twitter API

consumer_key = 'x1ImslwHENof8RIstPS6itXtFQ'
consumer_secret = 'OJgsR3xnITHPTMUx7qEfvp3d1Zwoa9tpW6lb6YBBC5Q1eAEoO5'
access_token = '944784851915304960-0aZ9wT0h2r3UZl1nC6C727a1LueSYoT'
access_token_secret = 'E22wQCMRkZ2NXgk6358KChra8R5njzAou0blkB8QLOVkR'

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

Search for tweets about the Warriors

warriors_tweets = tweepy.Cursor(api.search, q='#Brooklyn Nets').items(100)

Perform sentiment analysis on tweets

positive_tweets = 0
negative_tweets = 0
neutral_tweets = 0

for tweet in warriors_tweets:
analysis = TextBlob(tweet.text)
if analysis.sentiment.polarity > 0:
positive_tweets += 1
elif analysis.sentiment.polarity < 0:
negative_tweets += 1
else:
neutral_tweets += 1

Print results

print("Positive tweets: ", positive_tweets)
print("Negative tweets: ", negative_tweets)
print("Neutral tweets: ", neutral_tweets)

##if positive_tweets > negative_tweets:

continue

#else:
##say the opposing team will win

`---------------------------------------------------------------------------
TweepError Traceback (most recent call last)
in
23 neutral_tweets = 0
24
---> 25 for tweet in warriors_tweets:
26 analysis = TextBlob(tweet.text)
27 if analysis.sentiment.polarity > 0:

4 frames
/usr/local/lib/python3.8/dist-packages/tweepy/cursor.py in next(self)
49
50 def next(self):
---> 51 return self.next()
52
53 def next(self):

/usr/local/lib/python3.8/dist-packages/tweepy/cursor.py in next(self)
241 if self.current_page is None or self.page_index == len(self.current_page) - 1:
242 # Reached end of current page, get the next page...
--> 243 self.current_page = self.page_iterator.next()
244 while len(self.current_page) == 0:
245 self.current_page = self.page_iterator.next()

/usr/local/lib/python3.8/dist-packages/tweepy/cursor.py in next(self)
130
131 if self.index >= len(self.results) - 1:
--> 132 data = self.method(max_id=self.max_id, parser=RawParser(), *self.args, **self.kwargs)
133
134 if hasattr(self.method, 'self'):

/usr/local/lib/python3.8/dist-packages/tweepy/binder.py in _call(*args, **kwargs)
251 return method
252 else:
--> 253 return method.execute()
254 finally:
255 method.session.close()

/usr/local/lib/python3.8/dist-packages/tweepy/binder.py in execute(self)
232 raise RateLimitError(error_msg, resp)
233 else:
--> 234 raise TweepError(error_msg, resp, api_code=api_error_code)
235
236 # Parse the response payload

TweepError: Twitter error response: status code = 401`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant