如何在laravel 5.1中使用socialize(facebook)

时间:2015-08-21 09:06:32

标签: facebook laravel

我关注this guide

我的Laravel\Socialite\SocialiteServiceProvider中的

config/app.php没问题,别名也应该没问题:'Socialite' => Laravel\Socialite\Facades\Socialite::class,

这是我的代码:

配置/ services.php

'facebook' => [    
        'client_id' => 'xxxx',
        'client_secret' => 'xxxxx',
        'redirect' => 'http://localhost:8000/auth/fb',
]

路线

Route::get('auth/fb', 'FBController@redirectToProvider');
Route::get('auth/fb/callback', 'FBController@handleProviderCallback');

控制器

namespace App\Http\Controllers;
use Socialite;
use Illuminate\Routing\Controller;
class FBController extends Controller`
{

    public function redirectToProvider()
    {
        return Socialite::driver('facebook')->redirect();
    }


    public function handleProviderCallback()
    {
        $user = Socialite::driver('facebook')->user();

    }
}

错误

FatalErrorException in FBController.php line 14: Class 'App\Http\Controllers\Socialite' not found

我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

Socialite;替换为use Socialize;以及社交名称将其替换为社交名称的所有实例

namespace App\Http\Controllers;
use Socialize;
use Illuminate\Routing\Controller;
class FBController extends Controller
{
    public function redirectToProvider()
    {
        return Socialize::driver('facebook')->redirect();
    }

    public function handleProviderCallback()
    {
        $user = Socialize::driver('facebook')->user();

    }
}