0

I am trying to follow a python networkx tutorial but its using the python-twitter library and that library deals badly with twitter rate limit compared to tweepy. I want to know how i can do the same thing in tweepy; specifically how do i get the getfriends API in tweepy? Here is the code using python-twitter:

from pylab import *
from networkx import *
import twitter
api = twitter.Api(consumer_key='consumer_key',
                      consumer_secret='consumer_secret',
                      access_token_key='access_token',
                      access_token_secret='access_token_secret')
friends = api.GetFriends()
G = XGraph()

for friend in friends:
    G.add_edge('myname',friend.name)

for friend in friends[-3:]:
    for user in api.GetFriends(friend.id):
            G.add_edge(friend.name,user.name)

I have tried something like this using tweepy:

auth = tweepy.OAuthHandler(API_KEY, API_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

api = tweepy.API(auth,wait_on_rate_limit=True)
Followers=[]
c=tweepy.Cursor(api.followers).items(100)
for user in c:
    print user.screen_name
    Followers.append(user.screen_name)

but now i dont know how to continue translating to tweepy to get friends of friends, specifically this part in python-twitter :

for friend in friends[-3:]:
    for user in api.GetFriends(friend.id):
            G.add_edge(friend.name,user.name)

Please help.

jxn
  • 7,685
  • 28
  • 90
  • 172

1 Answers1

1

There are couple of handy methods that you can always use in order to access the required information.

API.friends_ids(id/screen_name/user_id)

This method is generally used to access the people being followed by a user (defined by either id/screen_name/user_id) ,The return value is a list of integers which represent the id of particular persons(unique) , Now if you would like to extract the persons followed by the particular user whom you are following then you can use something like:

people_followed_by_me = API.friends_ids('@Your_username123')
for person in people_followed_by_me:
    API.friends_ids(person)

API.followers_ids(id/screen_name/user_id)

This method is used to access the users which are following you , you can also extract the followers or friends of other people by just passing their username/id in the above mentioned functions.

You can always refer this documentation to clear further doubts.

ZdaR
  • 22,343
  • 7
  • 66
  • 87