特定 Twitter 用户未返回带有 user_timeline() 的推文
Specific Twitter users not returning tweets with user_timeline()
我正在尝试从不同的用户那里获取最新的推文,除了 this user 之外,我用完全相同的代码尝试过的每条推文都有效。这是我试过的代码:
import tweepy
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
tweet = api.user_timeline(screen_name='millions',
# 200 is the maximum allowed count
count=1,
include_rts=False,
tweet_mode='extended',
exclude_replies=True,
include_entities=True
)
print(tweet)
它只是为我打印 []
,如果我将用户更改为其他人,它会正常工作。
碰巧它带来了“计数”的数量,然后进行了过滤(在本例中为 rt 和回复)。来自 doc:
exclude_replies:
Using exclude_replies with the count parameter will mean you will receive up-to count tweets — this is because the count parameter retrieves that many Tweets before filtering out retweets and replies.
include_rts:
When set to false , the timeline will strip any native retweets (though they will still count toward both the maximal length of the timeline and the slice selected by the count parameter)
因此,如果您只带一个并且它是一个 rt(或回复),您将得到一个空列表。
带1个和200个是一样的,都算一个api来电。所以最好多带点,留在第一个:
tweet = api.user_timeline(screen_name='millions',
count=200,
include_rts=False,
tweet_mode='extended',
exclude_replies=True,
include_entities=True
)
# keep only the first tweet
tweet = tweet[:1]
我正在尝试从不同的用户那里获取最新的推文,除了 this user 之外,我用完全相同的代码尝试过的每条推文都有效。这是我试过的代码:
import tweepy
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
tweet = api.user_timeline(screen_name='millions',
# 200 is the maximum allowed count
count=1,
include_rts=False,
tweet_mode='extended',
exclude_replies=True,
include_entities=True
)
print(tweet)
它只是为我打印 []
,如果我将用户更改为其他人,它会正常工作。
碰巧它带来了“计数”的数量,然后进行了过滤(在本例中为 rt 和回复)。来自 doc:
exclude_replies:
Using exclude_replies with the count parameter will mean you will receive up-to count tweets — this is because the count parameter retrieves that many Tweets before filtering out retweets and replies.
include_rts:
When set to false , the timeline will strip any native retweets (though they will still count toward both the maximal length of the timeline and the slice selected by the count parameter)
因此,如果您只带一个并且它是一个 rt(或回复),您将得到一个空列表。
带1个和200个是一样的,都算一个api来电。所以最好多带点,留在第一个:
tweet = api.user_timeline(screen_name='millions',
count=200,
include_rts=False,
tweet_mode='extended',
exclude_replies=True,
include_entities=True
)
# keep only the first tweet
tweet = tweet[:1]