Skip to content

Instantly share code, notes, and snippets.

@warlock
Last active December 8, 2020 19:33
Show Gist options
  • Save warlock/56bf4f634ebfeb223e6f8079a9e53d90 to your computer and use it in GitHub Desktop.
Save warlock/56bf4f634ebfeb223e6f8079a9e53d90 to your computer and use it in GitHub Desktop.
Instagram Get ID from URL or Short
const shortcodeToInstaID = Shortcode => {
var char
var id = 0
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'
for (var i = 0; i < Shortcode.length; i++) {
char = Shortcode[i]
var mul = id * 64
id = mul + alphabet.indexOf(char)
}
return id
}
function getInstagramUrlFromMediaId(media_id) {
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
var shortenedId = '';
media_id = media_id.substring(0, media_id.indexOf('_'));
while (media_id > 0) {
var remainder = bigInt(media_id).mod(64);
media_id = bigInt(media_id).minus(remainder).divide(64).toString();
shortenedId = alphabet.charAt(remainder) + shortenedId;
}
return 'https://www.instagram.com/p/' + shortenedId + '/';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment