检索Twitter数据

时间:2015-03-13 20:18:30

标签: python twitter tweepy

我使用下面的代码使用tweepy检索Twitter主题标签数据,但此代码仅检索推文消息和创建的时间,但我需要检索该主题标签的元数据,任何帮助!!

   import tweepy 
   from tweepy import Stream
   from tweepy import OAuthHandler
   from tweepy.streaming import StreamListener
   import json
   import datetime 


   #setting up the keys
   consumer_key = '-------'
   consumer_secret = '----------'
   access_token = '--------'
   access_secret = '-----------'



  auth = OAuthHandler(consumer_key, consumer_secret)
  auth.set_access_token(access_token, access_secret)

  def date_range(start,end):
  current = start
  while (end - current).days >= 0:
  yield current
  current = current + datetime.timedelta(seconds=1)  

 class TweetListener(StreamListener):
   def on_status(self, status):
    #api = tweepy.API(auth_handler=auth)
    #status.created_at += timedelta(hours=900)

    startDate = datetime.datetime(2014, 03, 11)
    stopDate = datetime.datetime(2014, 03, 13)
    for date in date_range(startDate,stopDate):
        status.created_at = date
        print "tweet " + str(status.created_at) +"\n"
        print status.text + "\n"  

   stream = Stream(auth, TweetListener(), secure=True, )

   t = u"#سوريا"
   stream.filter(track=[t])

1 个答案:

答案 0 :(得分:0)

这可能有所帮助,a full specification of the status object