Cannot connect to Facebook with curl request

I created a simple Facebook application a few weeks ago. I got user information through the Facebook API, asking for permission from users. But he stopped working last week for nothing, and since then I have been looking for an answer.

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

When a cURL request is made to the Facebook Open Graph URL, the request fails either with error number 7 or 28. They are both error codes for the impossibility of connecting to the site or receiving time.

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

The hosting has an SSL certificate, has cURL, etc. And it worked fine a while ago. I read various topics and posts about it, 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 PHP methods, the PHP SDK, I realized that I do not need to send an access token, since it will set it if the access token is not in the $ parameters.
  • It goes to the makeRequest () method in sdk and returns false from curl_exec.
+6
source share
1 answer

This is apparently due to the cyclic structure of the DNS on Facebook. I assume that one of the Facebook addresses failed, and the server was still trying to connect to this address due to the DNS cache.

The host provider had to clear its DNS caches to solve the problem.

For more information on circular DNS, you can visit http://en.wikipedia.org/wiki/Round-robin_DNS .

+4
source

Source: https://habr.com/ru/post/912844/


All Articles