【发布时间】:2015-09-18 18:25:17
【问题描述】:
经过两天的研究,我没能找到我的问题/问题的答案/解决方案。所以,我在这里。如果它已经发布在某个地方,请原谅我,我会很感激这个链接。所以...
我有一个应用程序可以根据主题标签获取 Instagram 内容/图像。我需要将所选图像从 instagram cdn (imageurl) 复制到我的服务器。
该应用程序直到最近才能正常运行...问题出在:
$img = "https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s320x320/e35/11848968_1650345541876481_204433741_n.jpg"
imagecreatefromjpeg($img);
错误输出为:未能打开流 - SSL 连接超时
如果是使用 “http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_7.jpg”作为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 上,scontent.cdinstragram 返回失败打开流并且亚马逊 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" />
同样的事情,适用于 distillery.s3.amazonaws.com 而不适用于 scontent.cdninstagram.com
我知道必须在 scontent 服务器中禁用通过 php 获取图像,但如果是这样,我怎样才能获取这些图像?
我已经尝试使用 users/userid/media_id 验证和列出用户的图像并提供访问令牌,这样我就可以获取 amazonaws url,但我仍然得到 scontent.cdninstagram imageurls =/
非常感谢!
【问题讨论】:
-
这更可能是您服务器上的问题,而不是 Instagram 上的问题。似乎有东西阻止了传出的 SSL 连接。您有可以与之交谈的服务器管理员吗?
-
您好,是的。我有 root 但机器有一个我可以交谈的网络管理员。关于在哪里/什么检查这个的任何提示?你有没有尝试过,它有效吗?
-
我真的不知道。您的第二个示例中的 curl 调用是否返回相同的错误?
-
对不起,我还不能给 cmets 打分,但如果你们回复有条理的建议答案,我会很高兴。非常感谢!
-
嗨,我在scontent.cdninstragram.com 上尝试了 wget,但没有成功...我可以连接,但没有收到数据。另一方面,当我尝试 wget distillery.s3.amazonaws.com 中的其他网址时,它工作正常。我已经向管理员发送了一条关于端口 443(或其他)上的 ssl 出站流量的消息。谢谢你的提示!赞赏!
标签: php curl instagram file-get-contents remote-server