經過兩天的研究,我沒有設法找到我的問題/問題的答案/解決方案。所以,我在這裏。對不起,如果它已經發布到某個地方,我會很感激鏈接。所以...Curl,file_get_contents和Instagram的CDN
我有一個應用程序,根據標籤獲取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 「作爲網址,沒有問題。
我也嘗試過其他解決方案,如使用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回報未能打開流和亞馬遜網址工作正常。
另一種方法我試過:
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
我知道得到一個不工作通過php的圖像必須在服務器中禁用,但如果是這樣,我怎麼可能獲得這些圖像?
我試過認證和與用戶/用戶名/ media_id列出用戶的圖像和令牌提供訪問,所以我會得到amazonaws網址,但仍然我得到scontent.cdninstagram imageurls =/
非常感謝!
這更可能是您的服務器上的問題,而不是Instagram的問題。似乎有東西阻塞了傳出的SSL連接。你有可以與之通話的服務器管理員嗎? –
你好,是的。我有根,但機器有一個網絡管理員,我可以交談。任何提示哪裏/要檢查這個?你有沒有嘗試過,它的工作原理? – marciop
我真的沒有想法。第二個例子中的curl調用是否返回相同的錯誤? –