尝试使用本地XAMPP安装(主机名:laravel.dev)使用适用于Laravel 5.5的Facebook PHP SDK
Facebook应用程序设置正确,通过Facebook登录,可以登录。 $ fbobject-> getRedirectLoginHelper()返回显然成功,但后续尝试获取accessToken会导致:
错误:
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Class 'Facebook\Helpers\Session' not found
控制器代码:
<?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);
}
}
我也尝试过SammyK Laravel安装,这也会产生同样的错误。