-
-
Save sclark39/9daf13eea9c0b381667b61e3d2e7bc11 to your computer and use it in GitHub Desktop.
var bigint = require( 'big-integer' ) | |
var lower = 'abcdefghijklmnopqrstuvwxyz'; | |
var upper = lower.toUpperCase(); | |
var numbers = '0123456789' | |
var ig_alphabet = upper + lower + numbers + '-_' | |
var bigint_alphabet = numbers + lower | |
function toShortcode( longid ) | |
{ | |
var o = bigint( longid ).toString( 64 ) | |
return o.replace(/<(\d+)>|(\w)/g, (m,m1,m2) => | |
{ | |
return ig_alphabet.charAt( ( m1 ) | |
? parseInt( m1 ) | |
: bigint_alphabet.indexOf( m2 ) ) | |
}); | |
} | |
function fromShortcode( shortcode ) | |
{ | |
var o = shortcode.replace( /\S/g, m => | |
{ | |
var c = ig_alphabet.indexOf( m ) | |
var b = bigint_alphabet.charAt( c ) | |
return ( b != "" ) ? b : `<${c}>` | |
} ) | |
return bigint( o, 64 ).toString( 10 ) | |
} | |
toShortcode( '908540701891980503' ) // s.b. 'ybyPRoQWzX' | |
fromShortcode( 'ybyPRoQWzX' ) // s.b. '908540701891980503' |
and obviously shortcode generated from this is wrong. Tried to find solution for that whole day, but it seems that Instagram API is just unusable crap, no wonder so many brutal Instagram scrapers arrived at npm within last two years :(
Hey @jamzy118 did you find a solution to your problem ?
I have the exact same.
I post a media through the Graph API and it answers me an ID, but the shortcode generated from this ID is wrong.
Received ID : 17889455560051444
Incorrect shortcode from this ID : _dxrQnDeT
Correct shortcode : CSZUyULIgWQ
ID from this shortcode : 2637230475367810448
Same problem as pierrocknroll ^
Same here. Spent 2 days trying to fix this basic conversion which FB could do it for us. It makes total sense.
For anyone comes across this... this short code converter only works to generate the ig_id, but the facebook graph api ids are different and this doesn't work for thate
Examples shown above:
17889455560051444
17883949432067035
These are both ids from the ig graph api
@blixit @sclark39 Yep, that doesn't work with Basic Display API :(
For example I have a post: https://www.instagram.com/p/BWsP42nAHbD?__a=1
(
__a=1
shows you raw JSON of this post)JSON above states that the post has ID
1561693048415483587
which is properly converted toBWsP42nAHbD
by this script.But if I download the same post through Basic Display API, this exact post comes as:
and obviously shortcode generated from this is wrong. Tried to find solution for that whole day, but it seems that Instagram API is just unusable crap, no wonder so many brutal Instagram scrapers arrived at npm within last two years :(