Find Instagram media url by ID

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