Python script to check if the Instagram user is private or public

47 Views Asked by At

I tried the old request URL in the code, but it did not work:

response = requests.get(f"https://www.instagram.com/api/v1/users/web_profile_info/?username={username}", headers=header)

Any other way to get the user details, especially to check if the user is private or public

1

There are 1 best solutions below

2
Xiddoc On

Instagram will attempt to block you if you don't use a matching User-Agent header. Although not perfect, and will probably get you IP-banned pretty quickly, this is a fix which works:


profile = requests.get(
    url="https://www.instagram.com/api/v1/users/web_profile_info/?username=" + username,
    headers={
        "user-agent": "Mozilla/5.0 (Linux; Android 12; T431D Build/SP1A.210812.016; wv) AppleWebKit/537.36 "
                      "(KHTML, like Gecko) Version/4.0 Chrome/117.0.0.0 Mobile Safari/537.36 Instagram "
                      "312.1.0.34.111 Android (31/12; 240dpi; 480x888; TCL; T431D; Rio; mt6761; it_IT; 548323740)"
    })

is_private = profile.json()['data']['user']['is_private']