Skip to content

Instantly share code, notes, and snippets.

@ziot
Created May 5, 2021 05:21
Show Gist options
  • Save ziot/54333c0ddbdc3cf834da8f13af80b50f to your computer and use it in GitHub Desktop.
Save ziot/54333c0ddbdc3cf834da8f13af80b50f to your computer and use it in GitHub Desktop.
import requests, json
def getFollowers(cursor, count):
variables = '{"userId":"2319408132","count":5000,"cursor":"'+cursor+'|'+count+'","withHighlightedLabel":false,"withTweetQuoteCount":false,"includePromotedContent":false,"withTweetResult":false,"withUserResults":false,"withNonLegacyCard":true,"withBirdwatchPivots":false}'
url = "https://twitter.com/i/api/graphql/GFLX4V1lUMJo8xxmRPXqUQ/Followers?variables={}".format(variables)
headers = {
"Cookie": "",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0",
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/json",
"X-Twitter-Auth-Type": "OAuth2Session",
"X-Twitter-Client-Language": "en",
"X-Twitter-Active-User": "yes",
"X-Csrf-Token": "",
"Authorization": "",
"Referer": "https://twitter.com/coin_artist/followers"
}
r = requests.get(url, headers=headers)
data = json.loads(r.text)
try:
for instructions in data["data"]["user"]["followers_timeline"]["timeline"]["instructions"]:
if instructions["type"] == "TimelineAddEntries":
for user in instructions["entries"]:
if user["content"]["entryType"] == "TimelineTimelineCursor":
# if user["content"]["cursorType"] == "Top":
if user["content"]["cursorType"] == "Bottom":
nextData = user["content"]["value"].split("|")
cursor = nextData[0]
count = nextData[1]
else:
try:
name = user["content"]["itemContent"]["user"]["legacy"]["name"]
screen = user["content"]["itemContent"]["user"]["legacy"]["screen_name"]
print(screen.encode("utf-8"))
except:
print("Failed: {0}".format(user["content"]))
except Exception as e:
print("Failed ({0}|{1}): {2}".format(cursor, count, e))
exit()
print(nextData)
return nextData
cursor = "1698851070430206586"
count = "1389680245111520887"
while True:
nextData = getFollowers(cursor, count)
cursor = nextData[0]
count = nextData[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment