Required "app_id" key not supplied in config
Hello,
I found a weird bug while using my facebook app credentials from services.php.
My config/laravel-facebook-sdk.php looks like this :
...
'facebook_config' => [
'app_id' => config('services.facebook.app_id'),
'app_secret' => config('services.facebook.app_secret'),
'default_graph_version' => 'v2.6',
],
...
my services.php contains those lines :
...
'facebook' => [
'app_id' => env('FACEBOOK_APP_ID', '123456789'),
'app_secret' => env('FACEBOOK_APP_SECRET', 'xxxxxx'),
'client_id' => env('FACEBOOK_CLIENT_ID', '987654321'),
'client_secret' => env('FACEBOOK_CLIENT_SECRET', 'yyyyyy'),
],
...
and my .env file is like this :
FACEBOOK_APP_ID=112233445566778899
FACEBOOK_APP_SECRET=zzzzzzz
Using php artisan tinker, I get the correct app_id value :
Psy Shell v0.8.1 (PHP 7.0.15 — cli) by Justin Hileman
>>> config('services.facebook.app_id')
=> "112233445566778899"
But as soon as I try to use the Facebook SDK, I get the following exception :
ErrorException in /Users/loranger/projects/myproject/vendor/facebook/graph-sdk/src/Facebook/Facebook.php line 139: Required "app_id" key not supplied in config and could not find fallback environment variable "FACEBOOK_APP_ID"
I manage my environment value this way in order to being able to deploy on production with a minimalistic .env file.
Anyone deploying on prod doesn't break the app, even if he haven't any access to the .env file.
On a development side, any developer of the team can simply override any default environment variable using the .env file without looking at any env() call in any file.
This solution worked fine until I tried to use it with LaravelFacebookSdk.
Why can't I use
'facebook_config' => [
'app_id' => config('services.facebook.app_id'),
instead of
'facebook_config' => [
'app_id' => env('FACEBOOK_APP_ID', '123456789'),
?
Is this config file is really used, or the package blindly use the env file? Did I miss something ?
I know this is older... I had the same exact problem but ran php artisan config:cache and it fixed the problem
@cbenjamin it worked for me too!
$config = array_merge([
'app_id' => getenv(static::APP_ID_ENV_NAME),
'app_secret' => getenv(static::APP_SECRET_ENV_NAME),
'default_graph_version' => static::DEFAULT_GRAPH_VERSION,
'enable_beta_mode' => false,
'http_client_handler' => null,
'persistent_data_handler' => null,
'pseudo_random_string_generator' => null,
'url_detection_handler' => null,
], $config);
If I switch the parameters for the array_merge call, it seems to work:
$config = array_merge($config, [
'app_id' => getenv(static::APP_ID_ENV_NAME),
'app_secret' => getenv(static::APP_SECRET_ENV_NAME),
'default_graph_version' => static::DEFAULT_GRAPH_VERSION,
'enable_beta_mode' => false,
'http_client_handler' => null,
'persistent_data_handler' => null,
'pseudo_random_string_generator' => null,
'url_detection_handler' => null,
]);