27

How to extract Instagram Profile picture using instagram API in android ? Or any other Method To extract Insta Profile Picture?

Community
  • 1
  • 1
Yash Arora
  • 360
  • 1
  • 5
  • 10

3 Answers3

49

By May 2023, to get Instagram profile URL via API, use this:

https://www.instagram.com/USERNAME/?__a=1&__d=1

Chhaileng
  • 2,428
  • 1
  • 27
  • 24
  • 2
    It is not giving me data if I am not logged into Instagram – Shrijan Regmi May 23 '21 at 13:39
  • @ShrijanRegmi sometimes you need to specify some headers like User-Agent. Eg. `curl -s -H 'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Instagram 105.0.0.11.118 (iPhone11,8; iOS 12_3_1; en_US; en-US; scale=2.00; 828x1792; 165586599)' 'https://www.instagram.com/USERNAME/?__a=1'` – Chhaileng May 23 '21 at 14:33
  • 1
    Neither of these appear to work anymore as of Sep 10, 2021. Perhaps instructions are missing from the answer but more likely instagram has disallowed these APIs – Daniel Kats Sep 10 '21 at 20:07
  • https://www.instagram.com/USERNAME/?__a=1 This is not working in my app. This link returns as error HTML code, – Krupali Shingala Apr 25 '22 at 11:55
  • 3
    as of recently instagram doesn't allow the use of the public API, I've tried it for multiple times all it returns is a redirect to the actual profile – unknown989 Jun 05 '22 at 21:12
  • 1
    use https://www.instagram.com//?__a=1&__d=1, it should work. – Vikrant Bhat Apr 05 '23 at 16:35
  • The currently latest noted answer https://www.instagram.com/USERNAME/?__a=1&__d=1 does not work for me since it blocks my access via server. It seems to be a CORS limit blocking data access from other servers (including Postman). – Terry Windwalker Jun 09 '23 at 14:59
  • OK, perhaps not CORS but it requires a token. It says `{"message":"Please wait a few minutes before you try again.","require_login":true,"status":"fail"}` so probably a valid Instagram access token is required. – Terry Windwalker Jun 11 '23 at 08:54
14

To get profile photo, use the function bellow:

function getPhoto(a) {
  
  // validation for instagram usernames
  var regex = new RegExp(/^(?!.*\.\.)(?!.*\.$)[^\W][\w.]{0,29}$/);
  var validation = regex.test(a);

  if(validation) {
  
    $.get("https://www.instagram.com/"+a+"/?__a=1")
    .done(function(data) { 

      // getting the url
      var photoURL = data["graphql"]["user"]["profile_pic_url_hd"];

      // update img element
      $("#photoReturn").attr("src",photoURL)
     
     })
    .fail(function() { 
      // code for 404 error 
      alert('Username was not found!')
    })
  
  } else {
  
    alert('The username is invalid!')
  }

}

    
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<img src="" id="photoReturn">

<br><br>

<input type="text" id="usernameInput">

<button onclick="getPhoto($('#usernameInput').val().trim())">Get profile photo</button>
Rodrigo Vieira
  • 165
  • 1
  • 4
1

Using the Instagram API users endpoint (https://api.instagram.com/v1/users/{user-id}/?access_token=ACCESS-TOKEN ) you will receive a response like this one:

{
    "data": {
        "id": "1574083",
        "username": "snoopdogg",
        "full_name": "Snoop Dogg",
        "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",
        "bio": "This is my bio",
        "website": "http://snoopdogg.com",
        "counts": {
            "media": 1320,
            "follows": 420,
            "followed_by": 3410
        }
}

Using this you can get the profile picture.

Ishara Madhawa
  • 3,549
  • 5
  • 24
  • 42