Where do I find the Instagram media ID of a image

后端 未结 15 1197

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:03

    Instagram deprecated their legacy APIs in support for Basic Display API during the late 2019

    In Basic Display API you are supposed to use the following API endpoint to get the media id. You will need to supply a valid access token.

    https://graph.instagram.com/me/media?fields=id,caption&access_token={access-token}
    

    You can read here on how to configure test account and generate access token on Facebook developer portal.

    Here is another article which also describes about how to get access token.

    0 讨论(0)
  • 2020-12-22 20:05

    Here's an even better way:

    No API calls! And I threw in converting a media_id to a shortcode as an added bonus.

    Based on slang's amazing work for figuring out the conversion. Nathan's work converting base10 to base64 in php. And rgbflawed's work converting it back the other way (with a modified alphabet). #teameffort

    function mediaid_to_shortcode($mediaid){
    
        if(strpos($mediaid, '_') !== false){
            $pieces = explode('_', $mediaid);
            $mediaid = $pieces[0];
            $userid = $pieces[1];
        }
    
        $alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
        $shortcode = '';
        while($mediaid > 0){
            $remainder = $mediaid % 64;
            $mediaid = ($mediaid-$remainder) / 64;
            $shortcode = $alphabet{$remainder} . $shortcode;
        };
    
        return $shortcode;
    
    }
    
    function shortcode_to_mediaid($shortcode){
    
        $alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
    
        $mediaid = 0;
    
        foreach(str_split($shortcode) as $letter) {
            $mediaid = ($mediaid*64) + strpos($alphabet, $letter);
        }
    
        return $mediaid;
    
    }
    
    0 讨论(0)
  • 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)"
    }
    
    0 讨论(0)
  • 2020-12-22 20:11

    Right click on a photo and open in a new tab/window. Right click on inspect element. Search for:

    instagram://media?id=

    This will give you:

    instagram://media?id=############# /// the ID

    The full id construct from

    photoID_userID

    To get the user id, search for:

    instapp:owner_user_id Will be in content=

    0 讨论(0)
  • 2020-12-22 20:12

    For a period I had to extract the Media ID myself quite frequently, so I wrote my own script (very likely it's based on some of the examples here). Together with other small scripts I used frequently, I started to upload them on www.findinstaid.com for my own quick access.

    I added the option to enter a username to get the media ID of the 12 most recent posts, or to enter a URL to get the media ID of a specific post.

    If it's convenient, everyone can use the link (I don't have any adds or any other monetary interests in the website - I only have a referral link on the 'Audit' tab to www.auditninja.io which I do also own, but also on this site, there are no adds or monetary interests - just hobby projects).

    0 讨论(0)
  • 2020-12-22 20:14

    In pure JS (provided your browser can handle XHRs, which every major browser [including IE > 6] can):

    function igurlretrieve(url) {
    
      var urldsrc = "http://api.instagram.com/oembed?url=" + url;
    
      //fetch data from URL data source
      var x = new XMLHttpRequest();
      x.open('GET', urldsrc, true);
      x.send();
    
      //load resulting JSON data as JS object
      var urldata = JSON.parse(x.responseText);
    
      //reconstruct data as "instagram://" URL that can be opened in iOS app
      var reconsturl = "instagram://media?id=" + urldata.media_id;
      return reconsturl;
    
    }
    

    Provided this is your goal -- simply opening the page in the Instagram iOS app, which is exactly what this is about -- this should do, especially if you don't want to have to endure licensing fees.

    0 讨论(0)
提交回复
热议问题