I\'m am looking for the MediaID of an Instagram image which has been uploaded. It should look like
1234567894561231236_33215652
edit
The iOS Instagram app has now registered for regular http links to open in the Instagram app and this deeplink methodology is no longer necessary.
old
Swift 4 short-code parsing solution
private static func instagramDeepLinkFromHTTPLink(_ link: String) -> String? {
guard let shortcode = link.components(separatedBy: "/").last else { return nil }
// algorithm from https://stackoverflow.com/a/37246231/337934
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
var mediaId: Int = 0
for (_, char) in shortcode.enumerated() {
guard let index = alphabet.index(of: char) else { continue }
mediaId = (mediaId * 64) + index.encodedOffset
}
return "instagram://media?id=\(mediaId)"
}