Accessing Instagram's JSON without logging in

Viewed 88

I'm attempting to access a user's public profile page's JSON to pull information from it, but I keep getting redirected to the login page. I was using this link which works only when logged in. https://www.instagram.com/{username}/?__a=1

Is there a way for me to grab this information without logging in? I'm using PHP right now. I want to change the static JSON file to hopefully the live Instagram link to get live updates.

<?php 
//This is hotpush.php
$string = file_get_contents("test.json");
$json_a = json_decode($string, true);


//var_dump(json_decode($string, true));
echo $json_a["graphql"]["user"]["edge_followed_by"]["count"];


?>

I have the file echoing to a webpage like so:

<!DOCTYPE html>
<html>
<body>
    <div class = "testing">
    <form action="hotpush.php" method = "post">
        <input type = "text" id = "businesst" name = "businessta"><br>
        <input type="submit" value="Submit">
        <div class="msg"></div>
    </form>
    </div>
    <script>
        document.querySelector(".testing form").onsubmit = function(event) {
            event.preventDefault();
            var form_data = new FormData(document.querySelector(".testing form"));
            var xhr = new XMLHttpRequest();
            xhr.open("POST", document.querySelector(".testing form").action, true);
            xhr.onload = function () {
                if (this.responseText.toLowerCase().indexOf("success12312414sadadasf1") !== -1) {
                    window.location.href = "thankyou.html";
                } else {
                    document.querySelector(".msg").innerHTML = this.responseText;
                }
            };
            xhr.send(form_data);
        };
    </script>
</body>
</html> 
1 Answers
function scrape_insta($username) {
    $insta_source = file_get_contents('http://instagram.com/'.$username);
    $shards = explode('window._sharedData = ', $insta_source);
    $insta_json = explode(';</script>', $shards[1]); 
    $insta_array = json_decode($insta_json[0], TRUE);
    return $insta_array;
}

Use this, i ve been using this from a long time

Related