【问题标题】:Instagram API - Media returned is cut offInstagram API - 返回的媒体被切断
【发布时间】:2017-08-30 04:24:56
【问题描述】:

我到处搜索,但没有一个链接解释或解决为什么会发生这种情况。

每当我向 Instagram 发出端点请求以获取图片时,给出的大部分图片 URL 都会被截断 - 与 Instagram 上的原始帖子相比,并非整张照片都在那里。在我看来,也许在逻辑上,被切掉的图像并不是完全正方形的图像。

有没有什么方法可以得到完整的图像,而不需要裁剪以使其适合精确的正方形?

谢谢。

编辑:刚刚意识到开发人员控制台中有一个非方形媒体选项,但是我检查了这个,但它似乎不起作用。

【问题讨论】:

    标签: instagram instagram-api endpoint


    【解决方案1】:

    在您的API客户端配置页面中有一个选项可以设置API返回非方形媒体,它在迁移选项卡中:

    【讨论】:

    • 这就是我已经指出的不起作用 - 它仍然只返回croppud方形媒体。我现在已经解决了问题
    • @LucaSarif 确保在更改设置后重新创建访问令牌;它不适用于已创建的令牌。
    • 做了很多次,甚至从一开始就创建了新的客户,并勾选了这个选项。我得出的结论是我必须批准我的应用程序,这永远不会发生,或者它只是坏了。 @史蒂文·肖伯特
    【解决方案2】:

    解决了。尽管这确实有效,但令人失望的是 Instagram 的非方形媒体功能并没有达到预期的效果。

    $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;
    

    编辑: 有时上面的内容可能无法按预期执行,我遇到了麻烦,制作了一些...... 26 行代码都是因为 instagram 无法修复一个简单的复选框!

    //'/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";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-14
      • 1970-01-01
      • 2019-06-14
      相关资源
      最近更新 更多