Facebook SDK v4 for PHP Minimal Example

前端 未结 8 982
夕颜
夕颜 2020-12-02 14:44

I\'m trying to get the minimal example

using Facebook\\FacebookSession;

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

// Use         


        
8条回答
  •  天命终不由人
    2020-12-02 15:25

    1. PHP Version 5.4.0 or higher is required.
    2. Facebook uses Implementations of PSR-4. Hence You dont have to use require or require_once or include or include_once.
    3. In PSR-4, you just need packagename(namespace) i.e. directory name and class file name only.It will register classes dynamically from given package name.Ex.:- use packaname\classname.
    4. You will find the file autoload.php in Facebook SDK Autoload root directory.
    5. use is used to load dynamic classes using spl_autoload_register
    6. Facebook register all library using autoload.php or autoload_fb.php
    7. You have to find autoload.php in your downloaded library like facebook-php-sdk-v4-4.0-dev/.
    8. If you just wants to use Facebook library from download source.Then you have to copy autoload.php in your root directory or in Facebook directory.
    9. defined constant for FACEBOOK_SDK_V4_SRC_DIR i.e. path of the facebook library
    10. You need to do as below to use in php

    Note: I have copied /var/www/stack/24006673/facebook-php-sdk-v4-4.0-dev/src/Facebook directory and /var/www/stack/24006673/facebook-php-sdk-v4-4.0-dev/autoload.php file in root directory /var/www/stack/24006673/

    define('FACEBOOK_SDK_V4_SRC_DIR','/var/www/stack/24006673/Facebook/');
    require_once("autoload.php");
    use Facebook\FacebookSession;
    use Facebook\FacebookRequest;
    use Facebook\GraphUser;
    use Facebook\FacebookRequestException;
    use Facebook\FacebookRedirectLoginHelper;
    FacebookSession::setDefaultApplication('YOUR_APP_ID','YOUR_APP_SECRET');
    

提交回复
热议问题