Where do I find the Instagram media ID of a image

后端 未结 15 1465

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 20:08

    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)"
    }
    

提交回复
热议问题