使用时间戳提取特定用户的所有推文

时间:2015-04-28 15:59:33

标签: python-2.7

我正在尝试提取特定人的所有推文和时间戳。我是python和tweepy的新手。我有来自互联网搜索的工作代码,但我希望只打印特定用户的所有推文。

import tweepy
# Authentication details. To  obtain these visit dev.twitter.com
consumer_key = 'nWGEdfoaBt7d6wWhiAw5Tw'
consumer_secret = 'qM4QfDPqG9JQp6n0fqTCMrj6LJjES6vu2IzqpZLc'
access_token = '2284416938-JbD4F32m9xQPMxKoh6UikpCLoJm8F6xy8wDPS9P'
access_token_secret = 'XvJZQWa6zz5vHcHkUcYBacQKZJE9pcxbpxUUgNo9rN4AG'

if __name__ == '__main__':
    # Create authentication token
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    api = tweepy.API(auth)

    print 'Getting statistics for @BarackObama:'

    # Get information about the user
    data = api.get_user('BarackObama')

    print 'Followers: ' + str(data.followers_count)
    print 'Tweets: ' + str(data.statuses_count)
    print 'Favouries: ' + str(data.favourites_count)
    print 'Friends: ' + str(data.friends_count)
    print 'Appears on ' + str(data.listed_count) + ' lists'
    print(data)

print(data)print(status)仅提供某些推文(并非全部)以及JSON格式的其他不需要的信息。      我发现只使用以下代码从家里提取推文和自己的时间线

statuses = tweepy.Cursor(api.user_timeline).items(2)
data = [s.text.encode('utf8') for s in statuses]
print data

1 个答案:

答案 0 :(得分:0)

无论如何,我通过传递screenname或twitter id在单个窗口下载推文的方式,它同时适用于多个用户

相关问题