1
私が選択したトピック(キーワード)を使用してTwitterからのつぶやきの感情分析にGoogleクラウドNL APIを使用するにはどうすればよいですか?私はどのように人々がPythonのNLライブラリ「TextBlob」を使用して、私が選択したトピックについて感じていることのTwitterを使用してPythonスクリプト(TwitterのAPI)を書くことができますGoogle Cloud NL APIを使用してセンチメント分析を行うにはどうすればよいですか?
import tweepy from textblob import TextBlob
# Step 1 - Authenticate
consumer_key= 'CONSUMER_KEY_HERE'
consumer_secret= 'CONSUMER_SECRET_HERE'
access_token='ACCESS_TOKEN_HERE'
access_token_secret='ACCESS_TOKEN_SECRET_HERE'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
#Step 3 - Retrieve Tweets
public_tweets = api.search('Trump')
#CHALLENGE - Instead of printing out each tweet, save each Tweet to a CSV file
#and label each one as either 'positive' or 'negative', depending on the sentiment
#You can decide the sentiment polarity threshold yourself
for tweet in public_tweets:
print(tweet.text)
#Step 4 Perform Sentiment Analysis on Tweets
analysis = TextBlob(tweet.text)
print(analysis.sentiment)
print("")