我正在一个网站上集成Facebook登录选项,在使用PHP调用Facebook API时遇到了一些问题。我实际收到的错误如下:
Failed to connect to graph.facebook.com port 443: Connection timed out
我已验证curl调用中的超时值是正确的,尝试通过SSH直接从服务器的命令提示符检查连接(正确响应ping,端口似乎打开并且有进程在侦听等)。然而,我使用了一个我在网上找到的简单curl片段,其他人也遇到过类似问题,我成功地进行了测试,似乎问题是间歇性/不一致的:有时它能够完美快速地工作,有时会加载几秒钟然后出现上述错误。
我非常怀疑错误是出现在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;
}
在这段代码中,任何一个 $fb->get() 调用失败了——有时是第一个调用、有时是图片调用,有时是好友调用。
[更新]
错误仍在发生,大约 90% 的调用都如此。我尝试直接通过 SSH 在服务器上进行 curl 调用 (curl -v graph.facebook.com
),得到了以下两个结果:
* Rebuilt URL to: graph.facebook.com/
* Trying 31.13.91.2...
* TCP_NODELAY set
* Trying 2a03:2880:f01b:1:face:b00c:0:1...
* TCP_NODELAY set
* Immediate connect fail for 2a03:2880:f01b:1:face:b00c:0:1: Network is unreachable
* Connected to graph.facebook.com (31.13.91.2) port 80 (#0)
> GET / HTTP/1.1
> Host: graph.facebook.com
> User-Agent: curl/7.50.2
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< WWW-Authenticate: OAuth "Facebook Platform" "invalid_request" "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api"
< Access-Control-Allow-Origin: *
< Pragma: no-cache
< Cache-Control: no-store
< x-fb-rev: 3274377
< Content-Type: application/json; charset=UTF-8
< x-fb-trace-id: A2OYZzFP3v8
< facebook-api-version: v2.4
< Expires: Sat, 01 Jan 2000 00:00:00 GMT
< Vary: Accept-Encoding
< X-FB-Debug: z9FEtq3Rlh8LyFn6pOIBZ5ZMCX+TY1jUD7iZ7ZRZ8/YGAsi035TbCP3qdBzqxDryvjJhKoKxnbAdvcxY/7r3Vg==
< Date: Mon, 04 Sep 2017 19:51:40 GMT
< Transfer-Encoding: chunked
< Connection: keep-alive
<
* Curl_http_done: called premature == 0
* Connection #0 to host graph.facebook.com left intact
和
* Rebuilt URL to: graph.facebook.com/
* Trying 31.13.91.2...
* TCP_NODELAY set
* Connected to graph.facebook.com (31.13.91.2) port 80 (#0)
> GET / HTTP/1.1
> Host: graph.facebook.com
> User-Agent: curl/7.50.2
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< WWW-Authenticate: OAuth "Facebook Platform" "invalid_request" "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api"
< Access-Control-Allow-Origin: *
< Pragma: no-cache
< Cache-Control: no-store
< x-fb-rev: 3274377
< Content-Type: application/json; charset=UTF-8
< x-fb-trace-id: BrIDaH8D8D5
< facebook-api-version: v2.4
< Expires: Sat, 01 Jan 2000 00:00:00 GMT
< Vary: Accept-Encoding
< X-FB-Debug: tYvsf7Nn2PVnHFkV40UUddjQGKzPl8XKfdNeiqu1CXZck5WuUUlcG9hoCAZQrOX93uS19m2JpAEu9DJ/YhSIeg==
< Date: Mon, 04 Sep 2017 19:54:54 GMT
< Transfer-Encoding: chunked
< Connection: keep-alive
<
* Curl_http_done: called premature == 0
* Connection #0 to host graph.facebook.com left intact
有人有关于这个问题的更多信息或可能的解释吗?