How do i get the screen names from a list of twitter IDs? I have the IDs saved in a pandas dataframe and have 38194 IDs that i wish to match to their screen names so i can do a network analysis. I am using python, but i am quite new to coding so i do not know if this is even possible? I have tried the following:
myIds = friend_list
if myIds:
myIds = myIds.replace(' ','')
myIds = myIds.split(',')
# Set a new list object
myHandleList = []
i = 0
# Loop trough the list of usernames
for idnumber in myIds:
u = api.get_user(myIds[i])
uid = u.screen_name
myHandleList.append(uid)
i = i+1
# Print the lists
print('Twitter-Ids',myIds)
print('Usernames',myHandleList)
#set a filename based on current time
csvfilename = "csvoutput-"+time.strftime("%Y%m%d%-H%M%S")+".csv"
print('We also outputted a CSV-file named '+csvfilename+' to your file parent directory')
with open(csvfilename, 'w') as myfile:
wr = csv.writer(myfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
wr.writerow(['username','twitter-id'])
j = 0
for handle in myHandleList:
writeline = myHandleList[j],myIds[j]
wr.writerow(writeline)
j = j+1
else: print('The input was empty')