Skip to content

Instantly share code, notes, and snippets.

@chrisyeung1121
Last active December 21, 2018 13:45
Show Gist options
  • Save chrisyeung1121/e3f338dfe5f41b9b1d569e4aa11ad8f6 to your computer and use it in GitHub Desktop.
Save chrisyeung1121/e3f338dfe5f41b9b1d569e4aa11ad8f6 to your computer and use it in GitHub Desktop.
// node ig-request.js username
// 1. visit www.instagram.com/username?__a=1
// 2. save it as ${%Y%m%d}-${username}.json and upload it to a Google Cloud Storage Bucket
// 3. Automatically renew cookies so we can continue ot obtain JSONs
// 4. deploy it as a Cloud Function (bonus)
// 5. Health Monitor and logging. (bonus)
const request = require('request');
const fs = require('fs');
const strftime = require('strftime');
const {Storage} = require('@google-cloud/storage');
const projectID = "sustained-spark-123456";
const bucket = 'instagram-raw-data';
const storage = new Storage({
projectId: projectID,
});
var options = {
url: `https://www.instagram.com/${process.argv.slice(2)}?__a=1`,
headers: {
'Cookie':
'mcd=3; mid=XBvBogAEAAGda3CixmCMbWl5pMqn; csrftoken=QSV3QpAgyrUgIfpMycNGhqYKWmucnAWr; ds_user_id=8743589261; sessionid=8743589261%3ArjB01ek5n3nFLs%3A2; rur=PRN; urlgen="{"112.119.204.208": 4760}:1ga1Fh:vGfO_5LpaPkv5-HN-X4DI4PtOg0"',
'upgrade-insecure-requests': 1
}
};
function callback(error, response, body) {
var dateStamp = strftime("%Y%m%d", new Date());
var username = process.argv.slice(2);
fs.writeFile(`output/${dateStamp}-${username}.json`, body, function (err) {
if (err) throw err;
console.log(body);
});
}
request(options, callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment