PHP code example of neha2601 / facebook-cake-component

1. Go to this page and download the library: Download neha2601/facebook-cake-component library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

neha2601 / facebook-cake-component example snippets




return [
    'Facebook' => [
        'AppId' => '1336289226489835',
        'AppSecret' => 'b2c01b4544a3e388ce84c41456dccaf3',
        'DefaultGraphVersion' => 'v2.2',
    ],
];

Configure::load('global', 'default');

   public function initialize()
    {
        parent::initialize();
        $this->loadComponent('Facebook');
    }

namespace App\Controller;

use Facebook\Facebook;

/**
 * Facebook login.
 */
class SocialDetailsController extends ApiController
{

    /**
     * Facebook login.
     */
    public function login()
    {
        $permissions = ['email']; // Optional permissions
        $callbackUrl = 'http://' . $_SERVER['SERVER_NAME'] . 'facebook-callback'; // Redirect URL
        $loginUrl = $this->Facebook->facebookLogin($permissions, $callbackUrl);
        $this->set('loginUrl', $loginUrl);
    }
    
     /**
     * facebook callback method.
     */
    public function facebookCallback()
    {
        $this->autoRender = false;
        $facebook = $this->Facebook->getAccessToken();
        return true; //Return in your page
    }
}