📜  Python Tweepy – 获取用户发布的推文数量

📅  最后修改于: 2022-05-13 01:55:18.678000             🧑  作者: Mango

Python Tweepy – 获取用户发布的推文数量

在本文中,我们将了解如何获取用户已发布/更新的状态/推文数量。 statuses_count 属性为我们提供了一个整数,表示用户发布的状态数。

识别在 GUI 中创建用户的日期:

在上述个人资料中,用户发布的状态数:13.2K(13、200+)

示例 1:考虑以下配置文件:

我们将使用用户 ID 来获取用户。上述配置文件的用户 ID 是 57741058。

# import the module
import tweepy
  
# assign the values accordingly
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
  
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  
# set access to user's access key and access secret 
auth.set_access_token(access_token, access_token_secret)
  
# calling the api 
api = tweepy.API(auth)
  
# the ID of the user
id = 57741058
  
# fetching the user
user = api.get_user(id)
  
# fetching the statuses_count attribute
statuses_count = user.statuses_count 
  
print("The number of statuses the user has posted are : " + str(statuses_count))

输出 :

The number of statuses the user has posted are : 13239

示例 2:考虑以下配置文件:

我们将使用屏幕名称来获取用户。上述个人资料的网名是 PracticeGfG。

# the screen name of the user
screen_name = "PracticeGfG"
  
# fetching the user
user = api.get_user(screen_name)
  
# fetching the statuses_count attribute
statuses_count = user.statuses_count 
  
print("The number of statuses the user has posted are : " + str(statuses_count))

输出 :

The number of statuses the user has posted are : 2265