Who is following who network graph taking too long time!

oauth
api

#1

Hi all,

As part of my research I am looking at a group of people and see who is following who. Right now, I am looking at 600+ people and see the networks inside this group. I am not interested in who they follow in general. I am only looking at the connections of this 600+ within the group and at the end will do a directed network graph. So the way I am doing is taking a looooong time and was wondering anybody can suggest anything. Here is the part of the code I have to do this. The way I am doing requires 450K search :frowning:

api = tweepy.API(auth, wait_on_rate_limit=True)

user_a = mylist
user_b = mylist
for everyname in user_a:
    a = everyname
    print(a)
    for each in user_b:
        b = each
        try : 
            relationships = api.show_friendship(source_screen_name= a, target_screen_name= b)
            if relationships[0].following:
                graph_a.append(relationships[0].screen_name)
                graph_b.append(relationships[1].screen_name)
                print(relationships[0].screen_name +"  " +"follows" + "  " + relationships[1].screen_name)
            if not relationships[0].following:
                print(relationships[0].screen_name + "  " + "NOT follow" + "  " + relationships[1].screen_name)
        except requests.ConnectionError as e:
            print("OOPS!! Connection Error. Make sure you are connected to Internet. Technical Details given below.\n")

mylist includes 600+ unique screen names.

Thank you!


#2

I am using twecoll for creating such networks.

Don’t use the friendship endpoint because it doesn’t scale. If you have less than 100 users you would only need 1 API call. The friendships/lookup returns relationships of 100 users at once: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friendships-lookup

Because you have more than 100 users, you should collect all followings of each user. friends/ids gives you 5k followings per call. Once you got all followings you can go through them to see which ones match the IDs of the other users you are interested in. If the people follow less than 5k accounts each, you only need 600 calls instead of 450 000.


#3

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.