skip to Main Content

Im working on a website using Laravel in a Docker container on local. The webserver used is Nginx.

Im trying to implement Facebook’s Graph API (the PHP API) and as Im developing on localhost and using Docker, any time I want to use the API I get:

Can’t Load URL: The domain of this URL isn’t included in the app’s
domains. To be able to load this URL, add all domains and subdomains
of your app to the App Domains field in your app settings.

I tried adding the domain I use locally myapp.local:3000, also <my ip>:3000 or localhost:3000 but nothing works.

Here is the code:

public function facebookRequest() {
    $fb = new FacebookFacebook([
        'app_id' => 'MY_APP_ID',
        'app_secret' => 'MY_APP_SECRET',
        'default_graph_version' => 'v8.0',
        ]);

    $callback = 'users/get-facebook-photos';
    $helper = $fb->getRedirectLoginHelper();
    $permissions = ['user_photos'];
    $data['fb_url'] = $helper->getLoginUrl($callback, $permissions);
    
    $loginUrl = $helper->getLoginUrl(base_url().'/users/get-facebook-photos', $permissions);

    echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
}

What I need to do to develop using Graph API and Docker? There’s some option to bypass domain filter or what should I do?

2

Answers


  1. Chosen as BEST ANSWER

    Well finally got a solution (not the one I wanted). I was using a custom domain defined on my host file. That didn't work for Facebook. I needed to use localhost (not even 127.0.0.1) and whitelist localhost on Facebook Developers.

    So, if you have this issue, you can do this workaround and use localhost instead of custom domain. Nevertheless, my ideal solution would be using custom domains.


  2. Seems like you’re using your application to request a token from facebook servers and when the token is created, you’ll end up being redirected on to the original destination. The redirect location cannot be "localhost" it should be a valid location … like a website. If you want to make this work locally you could edit your /etc/hosts file to map local.example.com to 127.0.0.1 and use this domain for redirections in tests/QA, so that when your app gets redirected, it attempts it via the localhost.

    Another suggestion (found by searching for the exact but more generic parts of the error "Can’t Load URL: The domain of this URL isn’t included in the app’s domains") suggests:

    add "https://apps.facebook.com/&quot; in valid OAuth redirect URIs under https://developers.facebook.com/apps/your-app-id/fb-login/settings/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search