问题
Trying to get socialite to work on my app. Facebook returns the The parameter app_id is required error.
Routes:
Route::get('/login/facebook', '\CommendMe\Http\Controllers\AuthController@redirectToProvider');
Route::get('/login/facebook/callback', '\CommendMe\Http\Controllers\AuthController@handleProviderCallback');
services.php:
'facebook' => [
'client_id' => env('426129694395672'),
'client_secret' => env('840fca14fc9fac4b592cd49f285c2ee9'),
'redirect' => 'http://localhost/login/facebook/callback',
],
AuthController.php
public function redirectToProvider() {
return Socialite::driver('facebook')->redirect();
}
public function handleProviderCallback() {
$user = Socialite::driver('facebook')->user();
$user->name;
}
When trying the /login/facebook route, facebook returns this error.
Why is this happening?
回答1:
Either use as
'client_id' => '426129694395672',
Or
'client_id' => env("FB_APP",'426129694395672'),
and use FB_APP = '426129694395672' in .env file
Instead
'client_id' => env('426129694395672'),
Using env('VarName') is to get value of environment variable named as VarName in .env file
回答2:
Assuming that you have the following in your .env file:
CLIENT_ID=426129694395672
CLIENT_SECRET=840fca14fc9fac4b592cd49f285c2ee9
The facebook[] in your services.php should be like this:
'facebook' => [
'client_id' => env('CLIENT_ID'),
'client_secret' => env('CLIENT_SECRET'),
'redirect' => 'http://localhost/login/facebook/callback',
],
来源:https://stackoverflow.com/questions/47363067/laravel-socialite-facebook-login-error-the-parameter-app-id-is-required