0

Trying to get Facebook PHP SDK working on Laravel 5.5, with local XAMPP installation (hostname: laravel.dev)

Facebook application is set-up correctly, and with the Facebook login, it's possible to login. $fbobject->getRedirectLoginHelper() returns apparently successful, however the subsequent attempt to get the accessToken results in:

Error:

 Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Class 'Facebook\Helpers\Session' not found

Controller Code:

    <?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Session;
use Facebook\Facebook;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //$this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $fb = new \Facebook\Facebook([
        'app_id' => '11111111111111111',
        'app_secret' => '1111111111111111111111111111111',
        'allowSignedRequest' => false,
        'default_graph_version' => 'v2.10',
        'default_access_token' => '1111111111111|1111111111111111111111'
        ]);

        $helper = $fb->getRedirectLoginHelper();
        $accessToken = $helper->getAccessToken();

        $permissions = ['email']; // Optional permissions
        $loginUrl = $helper->getLoginUrl('http://laravel.dev/home', $permissions);

        $passdata = array(
                'loginUrl' => $loginUrl,
                );

        return view(('home.test'), $passdata);

    }
}

I also tried the SammyK Laravel installation, and that also produces the same error.

stoneferry
  • 177
  • 1
  • 2
  • 11
  • Possible duplicate of [Error: Class 'Facebook\FacebookSession' not found with the facebook PHP SDK](https://stackoverflow.com/questions/23569934/error-class-facebook-facebooksession-not-found-with-the-facebook-php-sdk) – Sapnesh Naik Feb 09 '18 at 16:18
  • The solutions in the linked article were tried and do not resolve the issue, although please note the linked article is PHP not Laravel. – stoneferry Feb 10 '18 at 17:28
  • Sounds like you are trying to use code that was written to work with the PHP SDK v4, with the v5 version ... the latter doesn’t have such a session class any more. – CBroe Feb 12 '18 at 07:55

1 Answers1

1

I'm not sure but you may use this

use Facebook\FacebookSession;

Reference here.

Md Rasel Ahmed
  • 1,025
  • 9
  • 12
  • Thanks for the response but it doesn't help I'm afraid. That namespace was tried. It's notable that my facebook vendor folder has no facebooksession.php file. In the article you link you'll see a response from a user who has the same problem: "Anro July 21, 2014 I used xampp to install wamp, and composer and got the php sdk installed. I’m unable to initialize the sdk! It cannot find the FacebookSession class! Here’s my code": – stoneferry Feb 11 '18 at 08:34