Tweety Python时间轴

时间:2018-04-12 13:36:00

标签: python tweepy

我试图检索特定帐户发布的推文。我确实用过 来自user_timeline库的tweepy参数,但它也包含来自具体Twitter用户的回复。有没有人知道如何省略它们?

Code:

import tweepy
consumer_key = key
consumer_secret = key
access_key = key
access_secret = key

def get_tweets(username):

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)

auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)

#set count to however many tweets you want; twitter only allows 200 at once
number_of_tweets = 20

#get tweets
tweets = api.user_timeline(screen_name = username,count = number_of_tweets)

#create array of tweet information: username, tweet id, date/time, text
tweets_for_csv = [[username,tweet.id_str, tweet.created_at, tweet.text.encode("utf-8")] for tweet in tweets]

print(str(tweets_for_csv))

1 个答案:

答案 0 :(得分:0)

exclude_replies作为kwarg传递。

tweets = api.user_timeline(screen_name=username, count=number_of_tweets, exclude_replies=True)

请参阅Twitters API documentation以获取可以传递的完整kwargs列表。