PHP - Retrieve Facebook image in Google Compute Engine

左心房为你撑大大i 提交于 2019-12-12 18:18:14

问题


I've tried to retrieve the image data of my Facebook profile picture, using both file_get_contents and curl.

The problem occurs on my Google compute engine instance, while on any other server (localhost - mamp, AWS) the script works fine.

An example for one of the scripts I was using

<?php

var_dump(
    json_decode(
        file_get_contents("https://graph.facebook.com/_FACEBOOK_ID_/picture?width=720&height=720")
    )
);

Please keep in mind that I've tried using the parameter redirect=false, and accessing the image url I've got in my json response returned false as-well.

Also, I've tried using wget in SSH to the image's url, which returned (403) Forbidden.

My assumption is that I need to configure something differently in my server, not PHP, but because I'm able to retrieve any other image, with the same script - I'm not sure what.


回答1:


I've already experienced this exact problem, Ignoring SSL verification while using cURL did the trick for me.

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Ignore SSL verification
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/_FACEBOOK_ID_/picture?width=720&height=720");
$data = curl_exec($ch);
curl_close($ch);

var_dump($data);


来源:https://stackoverflow.com/questions/38014596/php-retrieve-facebook-image-in-google-compute-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!