Where do I find the Instagram media ID of a image

后端 未结 15 1195

I\'m am looking for the MediaID of an Instagram image which has been uploaded. It should look like

1234567894561231236_33215652

15条回答
  •  囚心锁ツ
    2020-12-22 19:53

    You can actually derive the MediaId from the last segment of the link algorithmically using a method I wrote about here: http://carrot.is/coding/instagram-ids. It works by mapping the URL segment by character codes & converting the id into a base 64 number.

    For example, given the link you mentioned (http://instagram.com/p/Y7GF-5vftL), we get the last segment (Y7GF-5vftL) then we map it into character codes using the base64 url-safe alphabet (24:59:6:5:62:57:47:31:45:11_64). Next, we convert this base64 number into base10 (448979387270691659).

    If you append your userId after an _ you get the full id in the form you specified, but since the MediaId is unique without the userId you can actually omit the userId from most requests.

    Finally, I made a Node.js module called instagram-id-to-url-segment to automate this conversion:

    convert = require('instagram-id-to-url-segment');
    instagramIdToUrlSegment = convert.instagramIdToUrlSegment;
    urlSegmentToInstagramId = convert.urlSegmentToInstagramId;
    
    instagramIdToUrlSegment('448979387270691659'); // Y7GF-5vftL
    urlSegmentToInstagramId('Y7GF-5vftL'); // 448979387270691659
    

提交回复
热议问题