Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
登录facebook php sdk 5后的重定向_Php_Facebook_Facebook Graph Api_Facebook Php Sdk - Fatal编程技术网

登录facebook php sdk 5后的重定向

登录facebook php sdk 5后的重定向,php,facebook,facebook-graph-api,facebook-php-sdk,Php,Facebook,Facebook Graph Api,Facebook Php Sdk,成功登录文件fb callback.php后,我遇到重定向问题。这行行不通:标题(“位置:http://website/project/main.php“,对,302)。在所有var\u dump之前,我已经标记了重定向应该可以工作,但它不会工作。它将返回index.php,并且在浏览器栏中是index.php之后的#u=.。cookies从facebook设置,登录页面也可以使用。这是什么原因 index.php session_start(); require_once __DIR__ .

成功登录文件
fb callback.php
后,我遇到重定向问题。这行行不通:
标题(“位置:http://website/project/main.php“,对,302)。在所有
var\u dump
之前,我已经标记了重定向应该可以工作,但它不会工作。它将返回index.php,并且在浏览器栏中是index.php之后的
#u=.
。cookies从facebook设置,登录页面也可以使用。这是什么原因

index.php

session_start();

require_once __DIR__ . '/facebook-sdk-v5/autoload.php';


$fb = new Facebook\Facebook([
  'app_id' => '',
  'app_secret' => '',
  'default_graph_version' => 'v2.4',
   'cookie' => true,
  ]);

$helper = $fb->getRedirectLoginHelper();
$permissions = ['email', 'user_friends', 'public_profile']; // optional
$loginUrl = $helper->getLoginUrl("http://website/project/fb-callback.php", $permissions);

echo '<a class="ui-btn" href="' . $loginUrl . '" id="fb09">Log in with Facebook!</a>';
session_start();

require_once __DIR__ . '/facebook-sdk-v5/autoload.php';


$fb = new Facebook\Facebook([
  'app_id' => '',
  'app_secret' => '',
  'default_graph_version' => 'v2.4',
   'cookie' => true,
  ]);


$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)) {  
  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());  

// The OAuth 2.0 client handler helps us manage access tokens  
$oAuth2Client = $fb->getOAuth2Client();  

// Get the access token metadata from /debug_token  
$tokenMetadata = $oAuth2Client->debugToken($accessToken);  
//echo '<h3>Metadata</h3>';  
//var_dump($tokenMetadata);  

// Validation (these will throw FacebookSDKException's when they fail)  
 $tokenMetadata->validateAppId('');
// If you know the user ID this access token belongs to, you can validate it here  
// $tokenMetadata->validateUserId('123');  
$tokenMetadata->validateExpiration();   

if (! $accessToken->isLongLived()) {  
  // Exchanges a short-lived access token for a long-lived one  
  try {  
    $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);  
  } catch (Facebook\Exceptions\FacebookSDKException $e) {  
    echo "<p>Error getting long-lived access token: " . $helper->getMessage() . "</p>";  
    exit;  
  } 
  //echo '<h3>Long-lived</h3>';  
  //var_dump($accessToken->getValue());  
}

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

// User is logged in with a long-lived access token.  
// You can redirect them to a members-only page.  

header("Location: http://website/project/main.php", true, 302);
    session_start();

require_once __DIR__ . '/facebook-sdk-v5/autoload.php';

$fb = new Facebook\Facebook([
  'app_id' => '',
  'app_secret' => '',
  'default_graph_version' => 'v2.4',
   'cookie' => true,
  ]);