Issue
I want to know if an instagram account is private or public by providing the username. It has to be in headless mode as I have to use this in backend.
I tried using beautifulsoup and loaded the target page source but couldn't find anything that specified the account status (private/public).
Solution
I tried inspecting the Network
of a simple GET to my IG profile (private) and a public IG profile. It was very easy to find out this:
In the response of this call:
https://www.instagram.com/api/v1/users/web_profile_info/?username=public_account_username
The JSON body has this field:
{
"data": {
"user": {
// other fields
"is_private": false,
// other fields
}
}
}
Obviously, it is set to true
whether it's private.
You can use both beautifulsoup
and requests
, but personally I prefer requests
. It it very simple performing a GET
and retrieving data.
But it needs some headers. Looks like this API is only accessible from apps and website, as I've read here.
import requests
header = {"User-Agent": "Instagram 219.0.0.12.117 Android"}
username = "your_account"
response = requests.get(f"https://www.instagram.com/api/v1/users/web_profile_info/?username={username}", headers=header)
if response.status_code in [200, 201]:
# user actually exists
is_private = response["data"]["user"]["is_private"]
Answered By - Marco Frag Delle Monache
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.