PHP - 在Google Compute Engine中检索Facebook图片 [英] PHP - Retrieve Facebook image in Google Compute Engine

查看:125
本文介绍了PHP - 在Google Compute Engine中检索Facebook图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用file_get_contents和curl检索我的Facebook个人资料图片的图像数据。

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

我的Google计算引擎实例出现问题,而在任何其他服务器(localhost - mamp,AWS)上,脚本工作正常。

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")
    )
);

请记住,我尝试使用参数 redirect = false ,并且访问我在我的json响应中的图像url返回false一样。

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.

此外,我尝试使用 wget 在SSH中的图像的url,它返回(403)禁止。

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

我的假设是,我需要配置不同的东西在我的服务器,而不是PHP,但因为我我可以使用相同的脚本检索任何其他图像 - 我不知道什么。

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.

推荐答案

我已经经历了这个确切的问题,
在使用cURL时忽略SSL验证对我来说是个窍门。

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);

这篇关于PHP - 在Google Compute Engine中检索Facebook图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆