无法使用curl请求连接到Facebook [英] Can not connect to Facebook with a curl request

查看:211
本文介绍了无法使用curl请求连接到Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个星期前我创建了一个简单的Facebook应用程序。我通过请求用户的权限通过Facebook API获取用户信息。但是它在上周停止工作,从那时起,我一直在寻找一个答案。

I have created a simple Facebook application some weeks ago. I was getting user information through the Facebook API by asking permission from the users. But it stopped working last week out of nothing and I have been looking for an answer since then.

基本上我曾经使用file_get_contents从Facebook API获取用户信息。但我试图将其改为cURL后,它开始失败,但仍然不工作。我尝试使用Facebook的PHP-SDK,甚至调试代码makeRequest方法,但我在所有方法中获得相同的返回。

Basically I used to use file_get_contents to get the user information from Facebook API. But I tried changing it to cURL after it started failing, but still not working. I tried using the Facebook PHP-SDK, even debugged the code to makeRequest method, but I get the same return in all methods.

当一个cURL请求到Facebook打开图形URL,请求失败,错误编号为7或28.它们都是无法连接到网站或超时的错误代码。

When a cURL request is made to Facebook Open Graph URL, the request fails either with error number 7 or 28. They are both error codes for unable to connect to the site or getting time out.

我的网站是在共享主机,我已经尝试使用cURL来获取其他网站,它的工作正常。但是当我尝试 http://www.facebook.com 时,cURL返回FALSE。

My site is on a shared hosting, I have tried using cURL to get other sites, and It works fine. But when I try to get even http://www.facebook.com, cURL returns FALSE.

托管有SSL证书,启用cURL等。它在一段时间以前工作正常。

The hosting has SSL certificate, has cURL enabled etc. And it was working fine some time ago. I have read through various threads and posts about this, tried many different cURL options, and none of them seem to work.

有没有想法?

$auth_url = "https://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($GLOBALS['canvas_page']) . "&scope=publish_stream,email";
$signed_request = $_POST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
    echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
    $_SESSION['oauth_token'] = $data['oauth_token'];
    $_SESSION['user_id'] = $data["user_id"];
    $user = new User($_SESSION['user_id'], $_SESSION['oauth_token']);



用户类



User class

function __construct($fid, $at) {
    $this->facebook = new Facebook(array(
                'appId' => "<APP_ID>",
                'secret' => "<FACEBOOK_SECRET_ID>",
            ));
    $this->fid = $fid;
    $this->token = $at;
    if ($data = $this->getGraph()) {
    ...
    }
}

public function getGraph() {
    $session = $this->facebook->getUser();
    if ($session) {
        try {
            $access_token = $this->facebook->getAccessToken();
            $attachment = array('access_token' => $access_token);
            //$result = $this->facebook->api('/' . $this->fid, 'GET', $attachment);
            $result = $this->facebook->api('/' . $this->fid, 'GET');
            return $result;
        } catch (FacebookApiException $e) {
            return false;
        }
    }
}

注意: / strong>

Notes:


  • 检查Facebook PHP SDK方法后,我意识到我不需要发送访问令牌,

  • 在sdk中使用makeRequest()方法,并从curl_exec返回false。

推荐答案

显然这与Facebook的循环DNS结构有关。我猜想Facebook的地址之一失败,并且服务器仍然尝试连接到该地址,因为DNS缓存。

Apparently this is related with the round-robin DNS structure of Facebook. I guess one of the addresses of the Facebook failed and the server was still trying to connect to that address because of the DNS cache.

主机提供商必须清除其DNS缓存才能解决问题。

The hosting provider had to clear their DNS caches to resolve the problem.

有关轮次的更多信息-robin DNS,您可以访问 http://en.wikipedia.org/wiki/Round-robin_DNS

For more information about the round-robin DNS, you may visit http://en.wikipedia.org/wiki/Round-robin_DNS.

这篇关于无法使用curl请求连接到Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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