'How to receive data from Instagram programmatically android

By referring to existing blogs like this I got to know it can be done adding ?__a=1 as a extension to link then it will return a jsonObject, sure it does but only in browser.

I tried this(Kotlin)

        Thread {
            var link = "https://www.instagram.com/reel/CZBE3OIJ4vB/?__a=1"
            Log.d(tag, "Requesting URL: $link")
            val reader =
                BufferedReader(InputStreamReader(URL(link).openStream(), "UTF-8"))
            var sResponse: String?
            var s = StringBuilder()

            while (reader.readLine().also { sResponse = it } != null) {
                s = s.append(sResponse)
            }
            Log.d(tag, "Returned Data  :${s.toString()}")
        }.start()

but it returns <!DOCTYPE html>

<!DOCTYPE html><html lang="en" class="no-js not-logged-in client-root touch">
<head>
<meta charset="utf-8">...

What should I do to receive jsonObject just like received browser



Solution 1:[1]

using the /?__a=1 at the end of the url you can get the user's JSON. Unfortunately this cannot be used frequently because Instagram is able to know. When your IP address goes into the Instagram blacklist you won't be able to get the JSON. You immediately notice when your IP address is in the blacklist because the url replies with an html page that corresponds to the Instagram login page. There are 2 ways to solve this problem: -1 Use Instagram API; -2 Change the IP address of the machine making the request each time;

I hope this helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andrea Damiano