Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full list of twitter "friends" using python and tweepy

By friends I mean all of the twitter users who I am following.

Is it possible using tweepy with python 2.7.6 to display a full list of all friends?

I have found it possible to display a list which contains some of my friends with the following code. After handling authorization 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 appears to be my 20 most recent friends on Twitter, the ct variable is equal to 20. This method excludes the rest of the users I am following on Twitter.

Is it possible to display all of the users I am following on twitter? Or at least a way to adjust a parameter to allow me to include more friends?

like image 971
John Avatar asked Sep 20 '14 00:09

John


People also ask

How do I find out how many followers I have on Tweepy?

In order to get the number of followers we have to do the following : Identify the user ID or the screen name of the profile. Get the User object of the profile using the get_user() method with the user ID or the screen name. From this object, fetch the followers_count attribute present in it.

How do I extract data from twitter using Tweepy?

Steps to obtain keys: – For access token, click ” Create my access token”. The page will refresh and generate access token. Tweepy is one of the library that should be installed using pip. Now in order to authorize our app to access Twitter on our behalf, we need to use the OAuth Interface.

How can I get more than 100 tweets on Tweepy?

If you need more than 100 Tweets, you have to use the paginator method and specify the limit i.e. the total number of Tweets that you want. Replace limit=1000 with the maximum number of tweets you want. Replace the limit=1000 with the maximum number of tweets you want (gist).


1 Answers

According to the source code, friends() is referred to the GET friends / list twitter endpoint, which allows a count parameter to be passed in:

The number of users to return per page, up to a maximum of 200. Defaults to 20.

This would allow you to get 200 friends via friends().

Or, better approach would be to use a Cursor which is a paginated way to get all of the friends:

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

See also:

  • incomplete friends list
  • Tweepy Cursor vs Iterative for low API calls
like image 93
alecxe Avatar answered Sep 23 '22 08:09

alecxe