获取用户id的列表';来自使用Tweepy的用户Twitter追随者

获取用户id的列表';来自使用Tweepy的用户Twitter追随者,twitter,tweepy,twitterapi-python,Twitter,Tweepy,Twitterapi Python,我已经编写了以下代码来获取一个用户名拥有的所有Twitter追随者的列表,但我只想获取用户id,因为这允许我在API的速率限制内做更多的事情。如何更改此代码以仅打印用户ID auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(key, secret) api = tweepy.API(auth) screen_name = "twitterusername" f

我已经编写了以下代码来获取一个用户名拥有的所有Twitter追随者的列表,但我只想获取用户id,因为这允许我在API的速率限制内做更多的事情。如何更改此代码以仅打印用户ID

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(key, secret)
api = tweepy.API(auth)

screen_name = "twitterusername"
  
friends = api.friends_ids(screen_name) 
  
print(screen_name + " is following :") 
for friend in friends: 
    print(api.get_user(friend).screen_name)

我有所有正确的授权密钥和令牌。

用户对象有一个
id
字段

print(screen_name + " is following :") 
for friend in friends: 
  print(api.get_user(friend).id)
如果您只对用户的ID感兴趣,请注意
api.friends\u IDs
已返回ID列表

friends = api.friends_ids('screen_name')
logging.info(friends)
# output: [324343434, 134343234567,...]