CakePHP FacebookSession class not found issue

2019-01-29 01:07发布

I'm trying use Facebook lib v4 to create a simple Facebook login.

I'm following Facebook guide and I'm stucked at begnning, CakePHP is not finding FacebookSession class, follow below the facts:

FacebookSession class path:

App/Lib/Facebook/src/Facebook

Use in Controller:

app::uses('FacebookSession', 'Facebook/src/Facebook');

I think the Issue is in this specific Facebook Lib because I'm using WideImage class and I'm applying the same logic to use the Class and is working Perfectly.

For the record I'm using PHP 5.4

1条回答
姐就是有狂的资本
2楼-- · 2019-01-29 01:31

Custom paths/packages need to be registered

First of all that's not how App::uses() works. Custom paths/packages need to be registered first, please refer to CakePHP: Unable to load class from custom package

Also the Lib folder is ment to hold 1st party libraries, 3rd party libraries like the Facebook SDK should go into the Vendor folder.

See also Cookbook > CakePHP Folder Structure

Use composer or the autoloader that ships with the SDK

In case you can't/don't want to use the recommended way of including the SDK, that is by installing it using composer (make sure you read the notes in Installing CakePHP with Composer when using composer), then you have to make sure that you include the autoload.php file that ships with the SDK, which should be as simple as requiring it in your bootstrap

require_once APP . 'Vendor' . DS . 'Facebook' . DS . 'autoload.php';

From there on you should be able to use the SDK classes as shown in the docs.

use Facebook\FacebookSession;

FacebookSession::setDefaultApplication('YOUR_APP_ID','YOUR_APP_SECRET');

$session = new FacebookSession('access-token');
查看更多
登录 后发表回答