0

I want to fetch the instagram followers count for various users from my app using jquery / javascript. I tried the below code but i see 404 error:

            var $url = 'https://api.instagram.com/v1/users/'+user_id+'/?access_token='+$access_token;
            $.ajax({
                method: "GET",
                url: $url,
                dataType: "jsonp",
                jsonp : "callback",
                success: function(data) {
                   console.log(data);
                }
            });

My access token is created with scope public_content.

Apart from this I also tried fetching the page content as below without access token:

    $.ajax({
                url: 'https://www.instagram.com/'+user_id+'/?__a=1',
                type: 'GET',
                data: {},
                dataType: jsonp,
                success: function(data) {
                    console.log(data);
                }
            });

But this throws CORS error. Please help.

Indraja
  • 29
  • 1
  • 6
  • Possible duplicate of [CORS error with ajax request](https://stackoverflow.com/questions/36568923/cors-error-with-ajax-request) – kk. Jun 08 '17 at 08:15

3 Answers3

0

I dont know what the data of instagram api look like but if its related to CORS error, try put https://cors-anywhere.herokuapp.com before your url. This error appears because you are missing headers. You can try searching for CORS topic on SO if you like more information.

Hieu Chu
  • 186
  • 2
  • 7
0

i have an example maybe it will help you :

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>tst</title>
<script src="../jq.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $(".send").click(function(){
            var user_id =  $("#user_id").val();
            var access = 'xxxxxxxxxxxxxxxxxxxxxxxxx'
            var my_url = "https://api.instagram.com/v1/users/"  + user_id + "/?access_token="+access
            $.ajax({
                type: 'GET',
                url: my_url,
                dataType: 'jsonp'
            }).done(function(response){
                $("#name").text(response.data.username);
                 document.getElementById("img").src = (response.data.profile_picture);
                 $("#follwers").text(response.data.counts.followed_by + " followers");
                 $("#post").text("have a  "+response.data.counts.media +" post");   
                 console.log(response);           
            });
        });
    });
</script>
</head>
<body>
   <div id="dv1">
       <p id="name"></p>
       <img src='' alt="enter a user id" class="img" id="img" /><br>
       <p id="follwers"></p>
       <br>
       <p id="post"></p>
    </div>
    <input type="search" id="user_id" placeholder="user id" />
    <input type="button" class ="send"  value="send" />

it will help you .check it :)

Omid Reza Heidari
  • 658
  • 12
  • 27
0

If your app is in sanboxmode you should add 1 or 2 people to show their deatails :

You can invite them and they should accept your invite (you can Create another acc to inviting):

For more information you can go to :

instagram official page for sanbox mode information

i hope that your problem will solve.let me know.

Omid Reza Heidari
  • 658
  • 12
  • 27