Facebook SDK PHP

415 views Asked by At

I have need your help about Facebook SDK with PHP in Yii Framework. But when I put all file in php-sdk which download from developer.facebook.com into portected/vendor and config in config/main.php. In file I use code:

require_once (Yii::app()->basePath . '/vendors/facebook-php-sdk/autoload.php');

use Facebook\FacebookSession; use Facebook\FacebookRequest; use Facebook\GraphUser; use Facebook\FacebookRequestException; use Facebook\FacebookRedirectLoginHelper;

But when I use: FacebookSession::setDefaultApplication(api_key,api_secret);

It shown me an error:

Class Facebook FacebookSession not found in......

Can you help me about this error.Thank all.

2

There are 2 answers

1
朱西西 On

Maybe you try this :

session_start();
define('FACEBOOK_SDK_V4_SRC_DIR', './facebook-php-sdk-v4/src/Facebook/');
require_once("./facebook-php-sdk-v4/autoload.php");

use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;

just only use "./facebook-php-sdk-v4/autoload.php" in your project

1
crafter On

Please include all class files.

require_once Yii::app()->basePath . '/vendors/facebook-php-sdk/autoload.php';       
require_once Yii::app()->basePath . '/vendors/facebook-php-sdk/src/Facebook/FacebookSession.php';
require_once Yii::app()->basePath . '/vendors/facebook-php-sdk/src/Facebook/FacebookRequest.php';
require_once Yii::app()->basePath . '/vendors/facebook-php-sdk/src/Facebook/GraphObject.php';
require_once Yii::app()->basePath . '/vendors/facebook-php-sdk/src/Facebook/GraphUser.php';
require_once Yii::app()->basePath . '/vendors/facebook-php-sdk/src/Facebook/FacebookSDKException.php';
require_once Yii::app()->basePath . '/vendors/facebook-php-sdk/src/Facebook/FacebookRequestException.php';

use Facebook\FacebookSession;