Instagram has restricted using the unpublic user info API to retrieve a user's follower count (i.e., fetch from https://www.instagram.com/<username>/?__a=1 directly). By investigation, the restriction makes accessing the specific URL without a cookie redirect to the login page. Hence, the primary workaround is to extract a cookie if necessary and append the specific header with the cookie.
I would recommend taking advantage of KV. Explicit speaking, the cookie is extracted via a login API (inspired by instagram-user-feed) and stored in KV. If it is already stored, Substats should omit this step. Then, the user info API is still used but with enhanced logic. Since we are actually fighting against Instagram, let's name it "Plan Rebel". We need to know that this workaround has the following limits:
Highly unstable
This workaround requires no login confirmation, including two-factor authorisation and unusual login attempt confirmation. The former can be configured manually, while the latter may be impossible to avoid. This means that the account owner needs to tell Instagram that "it was me" tried to log in to my account every time the confirmation is prompted. Although the workaround has introduced a cookie caching mechanism to mitigate this limitation, it is still tremendously annoying for production.
Instagram can further restrict this workaround one day.
Limited resource: Cloudflare Worker free plan is used. KV is absolutely not unlimited. Yet I reckon it's sufficient.
Instagram has restricted using the unpublic user info API to retrieve a user's follower count (i.e., fetch from
https://www.instagram.com/<username>/?__a=1
directly). By investigation, the restriction makes accessing the specific URL without a cookie redirect to the login page. Hence, the primary workaround is to extract a cookie if necessary and append the specific header with the cookie.I would recommend taking advantage of KV. Explicit speaking, the cookie is extracted via a login API (inspired by instagram-user-feed) and stored in KV. If it is already stored, Substats should omit this step. Then, the user info API is still used but with enhanced logic. Since we are actually fighting against Instagram, let's name it "Plan Rebel". We need to know that this workaround has the following limits: