【发布时间】:2018-01-28 07:04:57
【问题描述】:
我正在从事一个项目,我从 Twitter API 流式传输推文,然后应用情绪分析并在交互式彩色地图上可视化结果。
我已经在 python 中尝试了 'tweepy' 库,但问题是它只检索很少的推文(10 或更少)。
另外,我将指定语言和位置,这意味着我可能会收到更少的推文!我需要成百上千条推文的实时流。
这是我尝试过的代码(以防万一):
import os
import tweepy
from textblob import TextBlob
port = os.getenv('PORT', '8080')
host = os.getenv('IP', '0.0.0.0')
# Step 1 - Authenticate
consumer_key= 'xx'
consumer_secret= 'xx'
access_token='xx'
access_token_secret='xx'
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('school')
for tweet in public_tweets:
print(tweet.text)
analysis = TextBlob(tweet.text)
print(analysis)
有没有更好的选择?我找到了“PubNub”,它是一个 JavaScript API,但现在我想要 python 中的东西,因为它对我来说更容易。
谢谢
【问题讨论】:
标签: python api twitter sentiment-analysis