Created
January 8, 2021 12:36
-
-
Save AvgustPol/14a6c2f1f753f2eb9f71f15b9ef0fda3 to your computer and use it in GitHub Desktop.
Get instagram profile photo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<script> | |
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> | |
<img src="" id="photoReturn"> | |
<br><br> | |
<input type="text" id="usernameInput"> | |
<button onclick="getPhoto($('#usernameInput').val().trim())">Get profile photo</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment