Codementor Events

💡 Tip Rapido: Fetch JSON data Desde un perfil publico simple sin Graph API

Published Jan 31, 2023

Cover image for 💡 Tip Rapido: Fetch JSON data Desde un perfil publico simple sin Graph API

Poleselfg

Poleselfg

Posted on Jan 14, 2021

Nunca quisieron obtener informacion de un perfil de instagram de una manera facil y sencilla? Bueno...

En una de esas navegaciones nocturnas de poco dormir, me encontre con esta solucion, que por lo que pude ver esta poco difundida.

https://www.instagram.com/{public_profile_name}/?__a=1

Resulta, que agregando el query ?__a=! al final de la direccion al perfil, podemos acceder a un JSON con toda la informacion publica del perfil.

por ejemplo:

https://www.instagram.com/refactordevs/?__a=1

nos devuelve el siguiente JSON:

Alt Text

Como pueden ver el JSON es muy y tenemos toda la informacion de la cuenta, inclusive, con unas pocas lineas de codigo, (en este caso en javascript), podemos obtener el feed:

async function getInstagramPictures (profileName) { const baseUrl = "https://www.instagram.com"; const profileUrl = `${baseUrl}/${profileName}`; const jsonDataUrl = `${profileUrl}/?__a=1`; const response = await fetch(jsonDataUrl); const jsonData = await response.json(); const pictures = jsonData.graphql.user.edge_owner_to_timeline_media.edges; if (response.ok) { return pictures; } else { throw new Error(pictures); }
}
getInstagramPictures("refactordevs") .then(pictures => console.log("Pictures:", pictures)) .catch(error => console.error("Error:", error));

Al realizar un bucle,se puede mostrar cada imagen o su miniatura.

Tambien podriamos traer las imagenes de perfil, o cualquier tipo de informacion.

solo basta con cambiar la siguiente linea:

const pictures = jsonData.graphql.user.edge_owner_to_timeline_media.edges;

Saludos! y espero que les sea util!

Sources:

Classic DEV Post from 2020:

js visualized

🚀⚙️ JavaScript Visualized: the JavaScript Engine

As JavaScript devs, we usually don't have to deal with compilers ourselves. However, it's definitely good to know the basics of the JavaScript engine and see how it handles our human-friendly JS code, and turns it into something machines understand! 🥳

Happy coding!


katongole_isaac profile image

infoxicator profile image

ayka_code profile image

perfect7m profile image

Once suspended, poleselfg will not be able to comment or publish posts until their suspension is removed.

Once unsuspended, poleselfg will be able to comment and publish posts again.

Once unpublished, all posts by poleselfg will become hidden and only accessible to themselves.

If poleselfg is not suspended, they can still re-publish their posts from their dashboard.

Note:

Thanks for keeping DEV Community 👩‍💻👨‍💻 safe. Here is what you can do to flag poleselfg:

Make all posts by poleselfg less visible

poleselfg consistently posts content that violates DEV Community 👩‍💻👨‍💻's code of conduct because it is harassing, offensive or spammy.

[Report other inappropriate conduct](javascript:void(0)😉

Unflagging poleselfg will restore default visibility to their posts.

Discover and read more posts from Federico Polesel
get started
post commentsBe the first to share your opinion
Show more replies