我正在我正在研究的网站上集成Facebook登录选项,并且在用PHP调用Facebook的API时遇到了一些问题.我得到的实际错误如下:
无法连接到graph.facebook.com端口443:连接超时
我已经验证了curl调用的超时值是正确的,我尝试通过SSH直接从服务器的命令提示符检查连接(ping正确,端口似乎是打开的,进程正在监听它等).然而,使用我在网上找到类似问题的简单卷曲片段,我设法轻松测试它,似乎问题是间歇性/不一致的:有时它完美无瑕地工作,有时它会加载几秒钟因上述错误而失败.
我非常怀疑这个错误是在Facebook的一面,但我无法弄清楚它是什么我做错了.我以前在PHP中使用过Facebook SDK,这是我第一次看到这个错误.
有没有其他人在遇到这个问题并修复它?
快速说明:这是我第一次在基于Symfony的项目中使用Facebook - 不要认为它在这种情况下是相关的,而是为了以防万一而将其丢弃.
相关摘要:
$fb = new \Facebook\Facebook(['app_id' => '[withheld]',
'app_secret' => '[withheld]',
'default_graph_version' => 'v2.10',]);
$fb->setDefaultAccessToken($accessToken); # Access token obtained from Facebook Login in JS, passed in post data.
try {
$basic_info_response = $fb->get('/me?fields=id,first_name,last_name,email,website');
if ($with_picture)
$profile_picture_response = $fb->get('/me/picture?width=720&height=720');
if ($with_friends)
$friends_response = $fb->get('/me/friends');
}
catch(\Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
}
catch(\Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
Run Code Online (Sandbox Code Playgroud)
在这段代码中,它在任何$ …
我在使用PHP调整图像大小时遇到问题;从我使用imagecreatefromstring或加载图像的那一刻起imagecreatefrompng,颜色似乎就会改变并变得褪色。
我知道我必须使用imagecreatetruecolor创建目标图像,但是我什至没有意识到这一点。
这里有一些例子来解释我得到的结果:
// This results in a discolored / faded image
$image = imagecreatefrompng('/path/to/my/image.png');
header('Content-Type: image/png');
imagepng($image);
die();
Run Code Online (Sandbox Code Playgroud)
// This also results in a discolored / faded image
$image = imagecreatefrompng('/path/to/my/image.png');
$info = getimagesize('/path/to/my/image.png');
$sourceWidth = $info[0];
$sourceHeight = $info[1];
$resizedImage = imagecreatetruecolor($sourceWidth, $sourceHeight);
imagecopyresampled($resizedImage, $image, 0, 0, 0, 0, $sourceWidth, $sourceHeight, $sourceWidth, $sourceHeight);
header('Content-Type: image/png');
imagepng($resizedImage);
die();
Run Code Online (Sandbox Code Playgroud)
// Obviously, this works flawlessly.
header('Content-Type: image/png');
echo file_get_contents('/path/to/my/image.png');
die();
Run Code Online (Sandbox Code Playgroud)
显然,我一定会遗漏一些东西,但是我一直在寻找我无法找到解决问题的任何方法和答案。
您遇到过这个问题吗?我应该怎么做呢?