Snbig/InstaTrack

'Username does not exist' on some accounts

rEnr3n opened this issue · 2 comments

$ python --version
Python 3.8.1
$ python InstaTracker.py -u g.mi
[-] Username does not exist
$ python InstaTracker.py -u 'g.mi'
[-] Username does not exist
$ python InstaTracker.py -u so_____y_
[-] Username does not exist
$ python InstaTracker.py -u 'so_____y_'
[-] Username does not exist
$ python InstaTracker.py -u _glam.diva_
[-] Username does not exist
$ python InstaTracker.py -u '_glam.diva_'
[-] Username does not exist

usernameToUserId() receives JSON from Instagram where the first result doesn't match the username being sought, and because the function only checks the first index for the right user, you're getting the 'does not exist' result being returned.
Instagram could be returning the results in this order because the profiles that are being returned in higher order have paid to make themselves the highest priority result...?

A fix for Instatrack might be that the results being returned are iterated through until the right username is found, such as in the sample code below.

`import requests
names = ["g.mi", "so_____y_", "glam.diva"]

for name in names:
data = requests.get(f"https://www.instagram.com/web/search/topsearch/?query={name}").json()

for user_data in data["users"]:
	if user_data["user"]["username"] == name:
		print(f"Name: {name}\nID: {user_data['user']['pk']}\n")`

Output:
Name: g.mi
ID: 1283104053

Name: so_____y_
ID: 1065286586

Name: glam.diva
ID: 2113578179

Snbig commented

Fixed by new commit: 7946c6c
@darylkell, Thank you for your editing suggestion.