Thanks to a HTTP call not very official, I find media ID, image URL, and user name of Instagram posts.
But I need the URL of each post on Instagram, and I don't know how to find it.
Is there an URL like instagram.com/something/{mediaID}
which redirect to instagram.com/p/{mediaSlug}
, or another method to find slug by media ID (without using the official API of course!) ?
For example, I've got :
Unique number : 1238578393243739028_1408429375
Media ID : 1238578393243739028
User ID : 1408429375
And I would :
https://www.instagram.com/p/BEwUHyDxGOU/
Thanks for your help !
Represents an Instagram album, photo, or video (uploaded video, live video, video created with the Instagram TV app, reel, or story).
The Instagram Basic Display API allows users of your app to get basic profile information, photos, and videos in their Instagram accounts. The API can be used to access any type of Instagram account but only provides read-access to basic data.
Java Solution :
public static String getInstagramPostId(String mediaId) {
String postId = "";
try {
long id = Long.parseLong(mediaId.substring(0, mediaId.indexOf('_')));
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
while (id > 0) {
long remainder = (id % 64);
id = (id - remainder) / 64;
postId = alphabet.charAt((int)remainder) + postId;
}
} catch (Exception e) {
e.printStackTrace();
}
return postId;
}
This can be helpful:
1) The algorithm to generate URL by yourself http://carrot.is/coding/instagram-ids
2) Also, Instagram has private API endpoint to generate URLs by media_id: https://i.instagram.com/api/v1/media/1212073297261212121_121212123111/permalink/ but it is protected with cookie sessionid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With