获取与推文对应的各种数据

fetching various data corresponding to a tweet

我正在尝试从 Twitter 获取数据进行处理。请查看代码,我想要与给定主题对应的特定推文对应的各种数据。我能够获取数据(created_at、文本、用户名、user_id)。当我尝试 fetch(location, followers_count, friends_count, retweet_count).

时显示错误
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import time
import json

ckey = '***********************'
csecret = '************************'
atoken ='*************************'
asecret = '**********************'

class listener(StreamListener):

  def on_data(self,data):
    try:
         all_data = json.loads(data)

         tweet = all_data["text"]

         username = all_data["user"]["screen_name"]

         timestamp = all_data["created_at"]

         user_id = all_data["id_str"]

         location = all_data["location"]

         followers_count = all_data["followers_count"]

         friends_count = all_data["friends_count"]

         retweet_count = all_data["retweet_count"]

         saveThis = str(time.time())+'::'+timestamp+'::'+username+'::'+user_id+'::'+tweet+'::'+followers_count+'::'+friends_count+'::'+retweet_count+'::'+location
         saveFile = open('clean2.txt','a')
         saveFile.write(saveThis)
         saveFile.write('\n')
         saveFile.close
         return True
     except BaseException, e:
         print 'failed on data,',str(e)
         time.sleep(5)

 def on_error(self, status):
     print status

auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=["tweepy"])#topic

它在 all_data["location"] 上失败的原因是推文没有这样的 属性:https://dev.twitter.com/overview/api/tweets

  • 与 friends_count 相同,followers_count - 它们是用户的属性,而不是推文。

代码不应在 all_date["retweet_count"] 上失败,因为推文有这样的 属性。

P.S。报告错误时请包括错误消息(即使您跳过完整的错误引用)。可以更轻松地帮助您,否则就必须猜测可能是什么错误。