Last active
September 18, 2017 13:23
-
-
Save gengue/c9e9c045ee9923853b01745a15e62740 to your computer and use it in GitHub Desktop.
How download all your photos from instagram
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
/* | |
* Download as plain file | |
* @param {String} filename | |
* @param {String} text data | |
*/ | |
function download(filename, text) { | |
var element = document.createElement('a'); | |
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); | |
element.setAttribute('download', filename); | |
element.style.display = 'none'; | |
document.body.appendChild(element); | |
element.click(); | |
document.body.removeChild(element); | |
} | |
/* | |
* Fetch all photos from a instagram account | |
* TODO: for now only donwload the first 1000 photos, but it's easy | |
* do a recursive function in order to checking if exist a next page available | |
* and build a total response. Also we coulud implement a browser download. | |
* @param {String} id | |
* @param {Number} queryId | |
*/ | |
function fetchAllData(id, queryId) { | |
const query = {id, first:1000}; | |
fetch(`https://www.instagram.com/graphql/query/?query_id=${queryId}&variables=${encodeURI(JSON.stringify(query))}`) | |
.then(response => response.json()) | |
.then(data => { | |
const urls = data.data.user.edge_owner_to_timeline_media.edges.map(i => i.node.display_url); | |
download('export.txt', urls.join('\n')); | |
}); | |
} | |
/* Init | |
* You need find your id and query_id, you can go to profile page and inspect | |
* the network using chrome development tools. | |
* check this screenshot https://www.screencast.com/t/osu14GvPDYrf | |
*/ | |
fetchAllData("322103628", 17888483320059182); | |
/* After run in your terminal: | |
* xargs -n 1 curl -O < export.txt | |
* or using wget: | |
* wget -i export.txt | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment