Last active
November 24, 2017 15:19
-
-
Save rafabarbosa/1adb8fdfe86d619e616e394ba07925bc to your computer and use it in GitHub Desktop.
Get 12 imagens from instagram profile throught instagram public api
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
<!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