Skip to content

Instantly share code, notes, and snippets.

@rafabarbosa
Last active November 24, 2017 15:19
Show Gist options
  • Save rafabarbosa/1adb8fdfe86d619e616e394ba07925bc to your computer and use it in GitHub Desktop.
Save rafabarbosa/1adb8fdfe86d619e616e394ba07925bc to your computer and use it in GitHub Desktop.
Get 12 imagens from instagram profile throught instagram public api
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<button onclick="nodes.forEach(myFunction)">Try it</button>
<p id="demo"></p>
<script>
// Exemplo de requisição GET
var ajax = new XMLHttpRequest();
// Seta tipo de requisição e URL com os parâmetros
ajax.open("GET", "https://www.instagram.com/raphaelrodriguez/?__a=1", true);
// Envia a requisição
ajax.send();
var nodes = [];
// Cria um evento para receber o retorno.
ajax.onreadystatechange = function() {
// Caso o state seja 4 e o http.status for 200, é porque a requisiçõe deu certo.
if (ajax.readyState == 4 && ajax.status == 200) {
var data = ajax.responseText;
data = JSON.parse(data);
// console.log(data.user.media.nodes);
nodes = data.user.media.nodes;
}
}
demoP = document.getElementById("demo");
function myFunction(item, index) {
console.log(item);
demoP.innerHTML = demoP.innerHTML + "index[" + index + "]: " + item + "<br>";
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment