Php 卷曲、文件获取内容和Instagram';s CDN

Php 卷曲、文件获取内容和Instagram';s CDN,php,curl,instagram,file-get-contents,remote-server,Php,Curl,Instagram,File Get Contents,Remote Server,经过两天的研究,我没能找到我的问题的答案。所以,我来了。请原谅,如果它已经张贴在某处,我将感谢链接。所以 我有一个基于标签获取instagram内容/图像的应用程序。我需要将所选图像从instagram cdn(imageurl)复制到我的服务器 直到最近,该应用程序才能正常工作。。。问题在于: $img = "https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s320x320/e35/11848968_165034554187

经过两天的研究,我没能找到我的问题的答案。所以,我来了。请原谅,如果它已经张贴在某处,我将感谢链接。所以

我有一个基于标签获取instagram内容/图像的应用程序。我需要将所选图像从instagram cdn(imageurl)复制到我的服务器

直到最近,该应用程序才能正常工作。。。问题在于:

$img = "https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s320x320/e35/11848968_1650345541876481_204433741_n.jpg"
imagecreatefromjpeg($img);
错误输出为:无法打开流-SSL连接超时

如果是使用 “”作为url,没有问题

我也尝试过其他解决方案,比如使用curl:

function getSSLPage($url) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // tried true/false
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false); // tried true/false
//curl_setopt($ch, CURLOPT_SSLVERSION,1); tried 1,2,3

$retorno['arquivo'] = curl_exec($ch); 
$retorno['status'] = curl_getinfo($ch);
$retorno['error']  = curl_error($ch);

curl_close($ch);
return $retorno;
}
var_dump(getSSLPage("https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/e35/11950482_1505223163123401_2062846740_n.jpg"));
这两个url都会发生同样的情况,scocontent.cdinstragram返回打开流失败,amazon url工作正常

我尝试的另一种方法是:

function img_create($filename, $mime_type) 
{  
  $content = file_get_contents($filename);
  $base64   = base64_encode($content); 
  return ('data:' . $mime_type . ';base64,' . $base64);
 }
?><img src="<?php print img_create('http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_7.jpg','jpeg'); ?>" alt="random logo" />
函数img\u create($filename,$mime\u type)
{  
$content=file\u get\u contents($filename);
$base64=base64_编码($content);
返回('data:'.$mime_type.'base64'.$base64);
}
?>“alt=”随机标识“/>
同样的东西,适用于dillery.s3.amazonaws.com,不适用于scocontent.cdnistagram.com

我知道通过php获取图像必须在ScoContent server中禁用,但如果是这样,我如何才能获取这些图像

我试着用users/userid/media\u id验证并列出用户的图像,并提供访问令牌,这样我就可以得到amazonaws url,但仍然得到了scocontent.cdnistagram ImageURL=/


非常感谢!

我确实尝试了下面的代码,即使在我的本地主机上,它也工作得非常好

<?php
    $data = file_get_contents('https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s320x320/e35/11848968_1650345541876481_204433741_n.jpg');
    file_put_contents('test.jpg', $data);

问题出在我的服务器的防火墙配置上。一旦网络管理员打开443(SSL端口)上的出站流量,上述所有示例都能正常运行


感谢您的支持,希望它能帮助面临同样问题的人们。

在instagram开发者网站中编辑您的客户端并启用
非方形媒体复选框。我可以使用文件获取内容将图像下载到本地。 请查看以下代码:

<?php

$content = file_get_contents ( 'https://api.instagram.com/v1/users/' . $id . '/media/recent/?access_token=' . $token );
$ins_media = json_decode ( $content, true );
$i = 0;
set_time_limit ( 0 );

foreach ( $ins_media ['data'] as $vm ) :

    if ($count == $i) {
        break;
    }
    $i ++;
    $img = $vm ['images'] ['low_resolution'] ['url'];
    $link = $vm ["link"];

    $path_parts = pathinfo ( $img ); 
    $imagData= explode("?",$path_parts ['basename']);
   $content = file_get_contents($img);

   file_put_contents("/xampp/htdocs/test/uploads/$imagData[0]",$content);

    ?>


与Instagram相比,您的服务器更可能出现问题。似乎有什么东西阻止了传出的SSL连接。您有可以联系的服务器管理员吗?您好,是的。我有root用户,但机器有网络管理员可以联系。关于在哪里/什么地方检查此问题,有什么提示吗?您在那里尝试过吗有效吗?我真的不知道。第二个示例中的curl调用是否返回相同的错误?很抱歉,我还不能为评论打分,但如果你们给出有组织的建议答案,我将很乐意回答。非常感谢!嗨,我在上尝试了wget,但没有成功…我可以连接,但没有收到任何数据。另一方面,什么时候我尝试了wget中的其他url…它工作正常。我已向管理员发送了一条关于端口443(或其他)上ssl出站流量的消息。感谢您的提示!谢谢!您好,谢谢提示,我尝试了,但没有成功。仍在等待网络管理员关于443上出站ssl的答复。