0

I have registered new app with facebook developer account. Following tutorial, I have this code:

    <?php
  // Remember to copy files from the SDK's src/ directory to a
  // directory in your application on the server, such as php-sdk/
  require_once('facebook/facebook.php');

  $config = array(
    'appId' => 'xxxxxxxxxxxx',
    'secret' => 'yyyyyyyyyyyyyy',
    'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
  );

  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();
?>
<html>
  <head></head>
  <body>

  <?php
    if($user_id) {

      // We have a user ID, so probably a logged in user.
      // If not, we'll get an exception, which we handle below.
      try {

        $user_profile = $facebook->api('/me','GET');
        echo "Name: " . $user_profile['name'];

      } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $login_url = $facebook->getLoginUrl(); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
      }   
    } else {

      // No user, print a link for the user to login
      $login_url = $facebook->getLoginUrl();
      echo 'Please <a href="' . $login_url . '">login.</a>';

    }

  ?>

  </body>
</html>

I set up on app dashboard: App Domains: buzzsu.com Website URL: buzzsu.com

Then I placed above code in www.buzzsu.com. When I visit that page it offers me to login. When I click login it gives me the following error:

Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.

How can I fix it?

torayeff
  • 9,296
  • 19
  • 69
  • 103
  • On the dashboard, did you add `buzzsu.com` or `www.buzzsu.com`? It matters. – Jamie Taylor Jan 24 '14 at 13:38
  • Ok! I edited app setting for www.buzzsu.com. Then in firefox I typed buzzsu.com it did not work, after I tried to type www.buzzsu.com and it works. What is the problem? – torayeff Jan 24 '14 at 13:41

1 Answers1

1

I had a same problem and I found that there was a mismatch in my "redirect_uri" and "Valid OAuth redirect URIs".

In my code, I had set:

redirect_uri = "http://www.website.com/validate.php";

But in my Facebook app I had set Valid OAuth redirect URIs:

http://website.com/validate.php

All I was missing "www". So I added another Valid OAuth redirect URI in my Facebook app:

http://www.website.com/validate.php




I worked like a magic for me.
Hope it will help you.

sohal07
  • 440
  • 8
  • 21