使用php sdk进行FB登录网站集成

时间:2016-11-10 11:59:23

标签: php facebook login sdk facebook-login

大家好,我的facebook登录使用php有问题。我已经做了一切恰当的假设,但仍然会出错。我爱一些有更多知识来帮助我解决这个问题。

以下是错误页面:

enter image description here



<?php
session_start();

ini_set('display_errors', '1');
// added in v4.0.0
require_once 'autoload.php';
require 'functions.php';  

use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\EntitiesAccessToken;
use Facebook\HttpClientsFacebookCurlHttpClient;
use Facebook\HttpClientsFacebookHttpable;

// init app with app id and secret
FacebookSession::setDefaultApplication( 'APP ID','APP SECRET' );
// login helper with redirect_uri
    $helper = new FacebookRedirectLoginHelper('http://www.xxxxxxxx.com/3rd_party/fbOAuth/fbconfig.php' );
try {
  $session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
  // When Facebook returns an error
} catch( Exception $ex ) {
  // When validation fails or other local issues
}
// see if we have a session
if ( isset( $session ) ) {
  // graph api request for user data
  $request = new FacebookRequest( $session, 'GET', '/me' );
  $response = $request->execute();
  // get response
  $graphObject = $response->getGraphObject();
     $fbid = $graphObject->getProperty('id');              // To Get Facebook ID
     $fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
     $femail = $graphObject->getProperty('email');    // To Get Facebook email ID
 /* ---- Session Variables -----*/
     $_SESSION['FBID'] = $fbid;           
        $_SESSION['FULLNAME'] = $fbfullname;
     $_SESSION['EMAIL'] =  $femail;
  checkuser($fuid,$ffname,$femail);
  header("Location: index.php");
} else {
  $loginUrl = $helper->getLoginUrl();
 header("Location: ".$loginUrl);
}
?>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

感谢所有人的帮助。我已经能够使用SDK v5.4解决问题并更改路径和重定向。

相关问题