Answer the question
In order to leave comments, you need to log in
Why is the MediaId of an Instagram post encoded this way?
Hello everyone who came to answer the question.
Here is an example of a link to one of the Instagram posts https://www.instagram.com/p/CWvxAY7B0ci/
1. Getting the MediaId from the shortcode.
The given shortcode in the CWvxAY7B0ci link is the base64 encoded MediaId of the post. It is decoded as follows:
1. The character index corresponding to the shortcode character is taken from the base64 table. Taking indexes for CWvxAY7B0ci we get 2,22,47,49,0,24,59,1,52,28,34 respectively. All this is collected in an array.
shortcode = 'CWvxAY7B0ci'
alphabet ={
"A": 0,
"C": 2,
"B": 1,
#и т.д. все значения
}
result = 0
for char in shortcode:
result = result * 64 + alphabet[char]
#результат 2715604631366879010
media_id = int('2715604631366879010')
alphabet ={
"A": 0,
"C": 2,
"B": 1,
#и т.д. все значения
}
short_code = ''
while media_id > 0:
remainder = media_id % 64
media_id = (media_id-remainder)/64
short_code = alphabet[remainder] + short_code
#результат CWvxAY7B0ci
Answer the question
In order to leave comments, you need to log in
Why are base64 encoding and decoding functions available in any language?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question