Complete twitter list of "friends" using python and tweepy

By friends, I mean all the Twitter users that I follow.

Is it possible to use tweepy with python 2.7.6 to display a complete list of all friends?

I found an opportunity to display a list containing some of my friends with the following code. After authorization processing, of course.

api = tweepy.API(auth) user = api.get_user('MyTwitterHandle') print "My Twitter Handle:" , user.screen_name ct = 0 for friend in user.friends(): print friend.screen_name ct = ct + 1 print "\n\nFinal Count:", ct 

This code successfully prints what seems to be my 20 most recent friends on Twitter, the ct variable is 20. This method excludes the rest of the users I visit on Twitter.

Can I display all the users I visit on Twitter? Or at least a way to tweak the setting to let me add more friends?

+6
source share
1 answer

According to the source code , friends() refers to the GET friends / list twitter endpoint, which allows passing the count parameter:

The number of users to return to the page, a maximum of 200. The default is 20.

This will allow you to get 200 friends through friends() .

Or the best approach is to use Cursor , which is a pagination , to get all the friends:

 for friend in tweepy.Cursor(api.friends).items(): # Process the friend here process_friend(friend) 

See also:

+9
source

Source: https://habr.com/ru/post/975563/


All Articles