Hello, I have altered/updated a script I found on Github to fetch a user’s followers on twitch. For some reason the script is fetching way more than the actual followers of the user. Here is the code I am using. Replace username with actual twitch profile name.
import json
import sys
import csv
import urllib.request
counter = 0
f = open('followers.csv','w',encoding='utf-8',newline="\n")
mywriter = csv.writer(f,dialect='excel',quoting=csv.QUOTE_MINIMAL)
mywriter.writerow(['Followed At (UTC)','Notifications?','User ID','User Name','User Created At (UTC)','User Updated At (UTC)','Display Name','Logo URL','Bio','User Type'])
url = "https://api.twitch.tv/kraken/channels/username/follows?direction=ASC&limit=100"
req = urllib.request.Request(url)
req.add_header("Client-ID","72v2al6ufhz1x2a32ynl68i6j8vku3")
response = str(urllib.request.urlopen(req).read().decode('utf-8'))
myjson = json.loads(response)
while (len(myjson['follows']) > 0):
for follower in myjson['follows']:
created_at = follower['created_at']
notified = follower['notifications']
user_id = follower['user']['_id']
user_name = follower['user']['name']
user_created = follower['user']['created_at']
user_updated = follower['user']['updated_at']
user_display = follower['user']['display_name']
if (follower['user']['logo'] != None):
logo_url = follower['user']['logo']
else:
logo_url = ""
if (follower['user']['bio'] != None):
user_bio = follower['user']['bio']
else:
user_bio = ""
user_type = follower['user']['type'].encode("utf-8")
mywriter.writerow([str(created_at),str(notified),user_id,str(user_name),str(user_created),str(user_updated),str(user_display),str(logo_url),str(user_bio),str(user_type)])
url = myjson['_links']['next']
response = str(urllib.request.urlopen(req).read().decode('utf-8'))
myjson = json.loads(response)
counter += 100
print(counter)
f.close