Php-graph-sdk: Failed to connect to graph.facebook.com port 443: Timed out

Created on 29 Mar 2017  路  10Comments  路  Source: facebookarchive/php-graph-sdk

I am on my local server here is what i try..

index.php

<?php 
session_start();
require_once __DIR__ . '\Facebook\autoload.php';
use Facebook\FacebookApp;
use Facebook\Facebook;
use Facebook\FacebookRequest;

$fb = new Facebook([
  'app_id' => '{app-id}',
  'app_secret' => '{app-secret}',
  'default_graph_version' => 'v2.5',
]);

$helper = $fb->getRedirectLoginHelper();
$permissions = ['email', 'user_likes']; // optional
$loginUrl = $helper->getLoginUrl('http://localhost/FB/login-callback.php', $permissions);

echo '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>';
?>

here is login-callback.php

<?php

session_start();
require_once __DIR__ . '\Facebook\autoload.php';
use Facebook\FacebookApp;
use Facebook\Facebook;
use Facebook\FacebookRequest;
$fb = new Facebook([
  'app_id' => '{app-id}',
  'app_secret' => '{app-secret}',
  'default_graph_version' => 'v2.5',
]);
 echo 'hi';
$helper = $fb->getRedirectLoginHelper();
try {
  $accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

if (isset($accessToken)) {
  // Logged in!

  $_SESSION['facebook_access_token'] = (string) $accessToken;

  // Now you can redirect to another page and use the
  // access token from $_SESSION['facebook_access_token']
}

?>

Most helpful comment

Ok

All 10 comments

Ok

I also have the same issue, but it's not happening all the time. I'm using Graph API v2.8 for all my api calls.

I noticed that @SammyK mentioned here https://github.com/SammyK/LaravelFacebookSdk/issues/14#issuecomment-66364982 that the Graph API doesn't have 100% uptime. Is that still the problem? That comment was posted on Dec 9, 2014 and I'm not sure if that's still valid.

Any help would be much appreciated!

I have job who run with Facebook sdk 24/7. I confirm sometimes Facebook return this error.

how do we handle it then?

I鈥檝e been getting this error sinxe yesterday on a job which has been working for a month. Once in a while I get in. I鈥檓 calling API 2.8 on laravel/socialite. Can anybody point me in right direction?

what is the connection port to graph.facebook.com? is 443 only ?

@Young-Je oh you fool , never post the acces_token in public , with this token anyone can post with your name and do whatever the fuck they want .Delete it !

@Young-Je I hope your token is not valid anymore, maybe a little bit activity on this thread will push you to change your comment?

I case any one still facing same problem,

i solve it by doing
do while loop , to ensure that post request is send

`public function send_msg($msg_tosend)
{
if ($msg_tosend) {// just ensure there is some thing to send
$url = $this->fb_graphv6 . $this->token;
// echo $url;
$ch = curl_init();
$headers = array("Content-type: application/json");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $msg_tosend);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ST;
do { // loop untill post request sent
$ST = curl_exec($ch);
if ($ST === false) {
$this->error_handler(curl_error($ch));
}

        } while ($ST === false);

        $result = json_decode($ST, true);
        curl_close($ch);
        return $result;

    } else {
        die('no messeg');
    }
}

`

Was this page helpful?
0 / 5 - 0 ratings

Related issues

igor84 picture igor84  路  8Comments

SammyK picture SammyK  路  8Comments

mohsenshakibafar picture mohsenshakibafar  路  4Comments

JenyaInfiapps picture JenyaInfiapps  路  6Comments

LeagueRivals picture LeagueRivals  路  4Comments