LaravelFacebookSdk icon indicating copy to clipboard operation
LaravelFacebookSdk copied to clipboard

Required "app_id" key not supplied in config

Open loranger opened this issue 9 years ago • 3 comments

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 ?

loranger avatar Feb 08 '17 22:02 loranger

I know this is older... I had the same exact problem but ran php artisan config:cache and it fixed the problem

cbenjamin avatar Sep 04 '17 22:09 cbenjamin

@cbenjamin it worked for me too!

Dilpenny avatar Aug 19 '19 10:08 Dilpenny

$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,
]);

zoranbogoevski avatar Nov 07 '20 22:11 zoranbogoevski