Laravel Socialite Facebook Login Error: The parameter app_id is required

别等时光非礼了梦想. 提交于 2020-01-15 06:35:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!