How to get Instagram Profile Picture?

折月煮酒 提交于 2020-01-01 19:12:46

问题


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


回答1:


Use one of these URL

  • https://www.instagram.com/USERNAME/?__a=1
  • https://i.instagram.com/api/v1/users/USER_ID/info/

NOTE: To get Instagram user id, use first URL with Instagram username




回答2:


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>



回答3:


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.



来源:https://stackoverflow.com/questions/50086945/how-to-get-instagram-profile-picture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!