2017-08-28 126 views
1

我到处找,但没有一个链接解释或给予修复,为什么发生这种情况。Instagram的API - 媒体返回被切断

每当我做一个端点请求的Instagram的图片,大多数图像的URL给被切断的 - 而不是整个照片是有比原来的岗位上Instagram的时候。在我看来,也许在逻辑上,被切断的图像是不完全正方形的图像。

有没有什么办法让完整的图像,无需裁剪,以适应它以精确的方?

谢谢。

编辑:刚刚意识到有在开发商控制台非正方形媒体的选择,但是我有这样的检查,但它似乎并不奏效。

回答

0

解决。虽然这确实奏效,但令人失望的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"; 
} 
0

有一个在API的客户端配置页面的选项设置API返回非方形介质,其迁移标签:

enter image description here

+0

这是我已经指出因为不工作 - 它仍然只返回croppud广场媒体。我现在已经解决了这个问题 –

+0

@LucaSarif确保在更改设置后重新创建访问令牌;它不适用于已经创建的令牌。 –

+0

做了这么多次,甚至从一开始就创建了新客户,并勾选了此选项。我得出的结论是,我必须批准我的应用程序,这种情况永远不会发生,或者它已被破坏。 @Steven Schobert –