プロジェクトに Facebook ログインを実装しようとしていますが、次のエラーが表示されます。
Middleware.php 行 69 の ClientException: クライアント エラー: 400
/Applications/MAMP/htdocs/laratest/vendor/guzzlehttp/guzzle/src/Middleware.php 69 行目
Middleware::GuzzleHttp{closure}(object(Response)) Promise.php 行 199 で
Promise::callHandler('1', object(Response), array(object(Promise), object(Closure), null)) で Promise.php 行 152
Promise::GuzzleHttp\Promise{closure}() で TaskQueue.php 行 60
CurlMultiHandler.php 行 96 の TaskQueue->run() で
私が経験した手順:
composer require laravel/socialite
&composer update
.私のconfig>services.appでは、
'facebook' => [
'client_id' => env('FB_CLIENT_ID'),
'client_secret' => env('FB_SECRET_ID'),
'redirect' => 'http://localhost.com:8888',
],
config>app.php
Laravel\Socialite\SocialiteServiceProvider::class,
に&'Socialite' => Laravel\Socialite\Facades\Socialite::class,
を追加ルートを正常にセットアップします。
Route::get('auth/facebook', 'Auth\AuthController@redirectToProvider');
Route::get('auth/facebook', 'Auth\AuthController@handleProviderCallback');
ブレード ファイルでリンクを正常にセットアップします。
Login with Facebook
Controller>AuthController.phpに、次を追加しました。
use Laravel\Socialite\Facades\Socialite; ** Beside everything that AuthController has, inside the AuthController class, I added:** public function redirectToProvider() { return Socialite::driver('facebook') ->scopes(['scope1', 'scope2'])->redirect(); } /** * Obtain the user information from Facebook. * * @return Response */ public function handleProviderCallback() { $user = Socialite::driver('facebook')->user(); // $user->token; }
またユーザーテーブル:
public function up() { Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('username'); $table->string('name'); $table->string('email')->unique(); $table->string('password', 60); $table->string('avatar'); $table->string('provider'); $table->string('provider_id'); $table->rememberToken(); $table->timestamps(); }); }
編集:一部
をコメントアウトする$user = Socialite::driver('facebook')->user();
と、リダイレクトされますlocalhost.com/auth/facebook
編集 2:
私の.env
ファイル:
'facebook' => [
FB_CLIENT_ID => '###',
FB_SECRET_ID => 'this-is-secret!',
],