验证facebook sdk后未加载登录成功页面

时间:2017-01-31 14:29:18

标签: php facebook facebook-graph-api

我想通过facebook sdk 5从facebook获取用户详细信息。 登录页面正在加载并要求登录与Facebook现在当我点击链接它重定向我到Facebook并要求允许共享详细信息我点击允许然后它重定向到回调页面但问题是回调页面是继续加载一些时间浏览器正在显示 连接已超时   website.com上的服务器响应时间过长。

以下是我正在使用的屏幕截图和代码

The connection has timeout

<?php
	
session_start();
require_once 'Facebook/autoload.php';
$fb = new Facebook\Facebook([
  'app_id' => 'xxxxxxxxxxxxxx', // Replace {app-id} with your app id
  'app_secret' => 'xxxxxxxxxxxxxxx',
  'default_graph_version' => 'v2.2',
  ]);
  
	$redirect = 'https://website.com/fb2/login.php';


	# Create the login helper object
	$helper = $fb->getRedirectLoginHelper();

	# Get the access token and catch the exceptions if any
	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 the 
	if (isset($accessToken)) {
	  	// Logged in!
	 	// Now you can redirect to another page and use the
  		// access token from $_SESSION['facebook_access_token'] 
  		// But we shall we the same page

		// Sets the default fallback access token so 
		// we don't have to pass it to each request
		$fb->setDefaultAccessToken($accessToken);

		try {
		  $response = $fb->get('/me?fields=email,name');
		  $userNode = $response->getGraphUser();
		}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;
		}


		// Print the user Details
		echo "Welcome !<br><br>";
		echo 'Name: ' . $userNode->getName().'<br>';
		echo 'User ID: ' . $userNode->getId().'<br>';
		echo 'Email: ' . $userNode->getProperty('email').'<br><br>';

		$image = 'https://graph.facebook.com/'.$userNode->getId().'/picture?width=200';
		echo "Picture<br>";
		echo "<img src='$image' /><br><br>";
		
	}else{
		$permissions  = ['email'];
		$loginUrl = $helper->getLoginUrl($redirect,$permissions);
		echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
	}

1 个答案:

答案 0 :(得分:0)

我发现这是托管问题,托管服务器阻止了导致此错误的内部请求。