Search code examples
instagraminstagram-apiendpoint

Instagram API - Media returned is cut off


I've searched everywhere but there is not one link explaining or giving a fix as to why this happens.

Whenever I make an endpoint request to Instagram for pictures, most of the image url's given are cut off - not the whole photo is there when compared to the original post on Instagram. It seems to me, and perhaps logically, that the images which are cut off are one's which are not exactly square.

Is there any way to get the full image, without the cropping to fit it in an exact square?

Thank you.

EDIT: Just realised there is a non-square media option in the developers console, however I have this checked but it does not seem to be working.


Solution

  • Solved. Although this does work, disappointing Instagram's non-square media feature doesn't do what it's meant to.

    $image_url = $insta_liked_array['data'][$image_key]['images']
    ['standard_resolution']['url'];
    
    //parse url to get last segment before image name
    
    $segments = explode('/', parse_url($image_url, PHP_URL_PATH));
    $segment_removal = $segments[5];
    
    //New Url without the segment
    $image_url_dynamic = str_replace("/" . $segment_removal,"",$image_url);
    
    echo $image_url_dynamic;
    

    Edit: Sometimes the above might not perform as expected, I have gone through the trouble of making something which will...26 lines of code all because instagram can't fix a simple checkbox!

    //'/e35/c' is a common string in each url, so from this we can take 
    //away the /c... section using this info
    //whatever index [e35] is, check if the next index has c as the first 
    //letter, if so, remove that part
    
    echo "Exploding url, checking for non-square media...\n\n";
    $segments = explode('/', parse_url($image_url, PHP_URL_PATH));
    
    if(in_array('e35', $segments)){
    //get the index of e35
    $e35_index = array_search('e35', $segments);
    //if the letter 'c' is in the next seg, remove it
    // to check if 'c' is in the next segment
    $c_segment = $segments[$e35_index + 1];
    
    if (strpos($c_segment, 'c') !== false) {
    echo "Non square media resolve in progress...\n\n";
    //get rid of that section +backslash, (replace with nothing)
    $image_url = str_replace("/" . $c_segment,"",$image_url);
    echo "New url has been made...\n\n\n\n" . $image_url;
    }
    elseif(strpos($c_segment, 'c') === false){
    echo "Square media detected, no need to remove a segment...\n\n";
    $image_url = $image_url;
    }
    else {
    echo "An error occured";
    }
    }
    else{
    echo "An error occured - url should contain 'e35' string";
    }