6

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.

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.

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.

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.

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.

Any ideas?

index.php

$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;
        }
    }
}

Notes:

  • After checking the Facebook PHP SDK methods, I've realized that I do not need to send access token, as it will set it if access token is not in the $params.
  • It goes down to makeRequest() method in sdk, and returns false from the curl_exec.
retri
  • 91
  • 1
  • 3
  • 11
  • can you post your app init & curl code please? – ShawnDaGeek Apr 10 '12 at 13:06
  • Any change to the network architecture? firewalls? ips? host files? can you ping graph.facebook.com from the command line? can you use curl as a command line with -v option in order to see more info? – Yaniro Apr 10 '12 at 13:26
  • I do not have shell access, the site is hosted on shared server. But the problem is fixed by clearing the DNS cache. It was related with the round-robin DNS technique used by Facebook. I cannot answer the question myself as I do not have enough rep. – retri Apr 10 '12 at 14:30
  • It would be helpful, if you can post your answer separately and selected it as the accepted anser. It will help those who are looking for unanswered questions. – Sudar Apr 11 '12 at 05:17

1 Answers1

4

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.

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

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

retri
  • 91
  • 1
  • 3
  • 11