douqi1625 2015-10-04 18:47
浏览 40

使用登录facebook实现cakephp auth的问题

I created an application using cakephp auth component in cakephp 2.6.2 version, now I also implement a login with facebook using facebook sdk, I am trying to follow this post How do I integrate Facebook SDK login with cakephp 2.x?, and for this I have downloaded the facebook-php-sdk-v4, however when I use the sentence

App::import('Vendor', 'facebook-php-sdk-v4-5.0-dev/src/Facebook'); 

and then call the Facebook class, I am having the error

Fatal error: Class 'Facebook' not found in C:\xampp\htdocs\exampleApp\app\Controller\AppController.php on line 34

I copied facebook SDK in exampleApp\app\Vendor and the folder is named facebook-php-sdk-v4-5.0-dev

my appControll here

    <?php

App::uses('Controller', 'Controller');
App::import('Vendor', 'facebook-php-sdk-v4-5.0-dev/src/Facebook');

class AppController extends Controller {



    public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array(
                'controller' => 'home',
                'action' => 'Page'
            ),
            'logoutRedirect' => array(
                'controller' => 'users',
                'action' => 'login'
            ),
            'authenticate' => array(
                'Form' => array(
                    'passwordHasher' => 'Blowfish'
                )
            ),
            'authorize' => array('Controller'),
            'authError' => false
        )
    );


    public function beforeFilter(){

        $this->Facebook = new Facebook(array(
            'appId'     =>  'App_ID_of_facebook',
            'secret'    =>  'App_Secret'

        ));

        $this->layout = 'bootstrap';
        $this->Auth->allow(
                            'login', 
                            'logout'
                    );

        $this->set('current_user', $this->Auth->user());
    }

    public function isAuthorized($user)
    {
        if(isset($user['role_id']) && $user['role_id'] === '1')
        {
            return true;
        }

        return false;

    }

}
?>

The problem is particularly in

$this->Facebook = new Facebook(array(
            'appId'     =>  'App_ID_of_facebook',
            'secret'    =>  'App_Secret'

        ));

is here where is returning Fatal error: Class 'Facebook' not found

thank you very much in advance to anyone who can help me

  • 写回答

1条回答 默认 最新

  • donglou8371 2015-10-05 16:04
    关注

    the problem was that the class "Vendor/facebook-php-sdk-v4-5.0-dev/src/Facebook/Facebok.php" had "namespace Facebook" therefore was in a different scope of my project, so the solution was to remove "namespace Facebook"

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题