CakePHP FacebookSession class not found issue

后端 未结 1 385
一个人的身影
一个人的身影 2020-12-21 22:00

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

相关标签:
1条回答
  • 2020-12-21 22:28

    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');
    
    0 讨论(0)
提交回复
热议问题