php - Facebook SDK returned an error: Connection timed out after 10001 milliseconds -
i have integrated facebook login (php sdk version 5.0.0) website. working fine in localhost. shows following error when have hosted in server;
facebook sdk returned error: connection timed out after 10001 milliseconds
i have changed 'site url' , 'oauth redirect uri' when hosted in server. necessary change else in app? have checked curl enabled in server, showing 'enabled' in php ini. php version 5.5.28.
my code given below;
index.php:
<?php session_start(); error_reporting(e_all); $path = realpath(dirname(__file__)); require $path .'/facebook-sdk-v5/autoload.php'; $fb = new facebook\facebook([ 'app_id' => 'xxxxxxx', 'app_secret' => 'xxxxxxxx', 'default_graph_version' => 'v2.4', ]); $helper = $fb->getcanvashelper(); // grab signed request entity $sr = $helper->getsignedrequest(); // user id if signed request exists $user = $sr ? $sr->getuserid() : null; if ($user) { try { // access token $accesstoken = $helper->getaccesstoken(); } catch (facebook\exceptions\facebooksdkexception $e) { // there error communicating graph echo $e->getmessage(); exit; } } else { $helper = $fb->getredirectloginhelper(); $permissions = ['public_profile','email','user_birthday','user_location']; // optional $callback = 'http://www.example.com/ret_page.php'; $loginurl = $helper->getloginurl($callback, $permissions); echo '<a href="' . $loginurl . '">log in facebook!</a>'; }
ret_page.php:
<?php session_start(); error_reporting(e_all); $path = realpath(dirname(__file__)); require $path .'/facebook-sdk-v5/autoload.php'; $fb = new facebook\facebook([ 'app_id' => 'xxxxxx', 'app_secret' => 'xxxxxxxxxxx', 'default_graph_version' => 'v2.4', ]); $helper = $fb->getredirectloginhelper(); try { $accesstoken = $helper->getaccesstoken(); } catch (facebook\exceptions\facebookresponseexception $e) { // when graph returns error echo 'graph returned error: ' . $e->getmessage(); exit; } catch (facebook\exceptions\facebooksdkexception $e) { // when validation fails or other local issues echo 'facebook sdk returned error: ' . $e->getmessage(); exit; } if (!isset($accesstoken)) { if ($helper->geterror()) { header('http/1.0 401 unauthorized'); echo "error: " . $helper->geterror() . "\n"; echo "error code: " . $helper->geterrorcode() . "\n"; echo "error reason: " . $helper->geterrorreason() . "\n"; echo "error description: " . $helper->geterrordescription() . "\n"; } else { header('http/1.0 400 bad request'); echo 'bad request'; } exit; } // logged in echo '<h3>access token</h3>'; var_dump($accesstoken->getvalue()); $fb->setdefaultaccesstoken($accesstoken); $res = $fb->get('/me?fields=id,name,gender,email,birthday,location'); $user = $res->getgraphobject(); // printing result print_r($user);
Comments
Post a Comment