7

I keep getting 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.

when I try to login a user with my PHP code snippet (see below). My Facebook settings are as follows:

App Domains: myappname-mynamespace.rhcloud.com www.myappname-mynamespace.rhcloud.com

Site URL: http://myappname-mynamespace.rhcloud.com/

Canvas Page: http://apps.facebook.com/myappname

Canvas URL: http://myappname-mynamespace.rhcloud.com/

Secure Canvas URL: https://myappname-mynamespace.rhcloud.com/

I've read similar questions here, here, here, here and here and they all seem to say the same thing: my Site URL (Website with Facebook Login) is incorrect.

But my Openshift URL is like this

http://myappname-mynamespace.rhcloud.com

so that's what I put in Facebook Site URL field. I have the following PHP code (index.php) in the root of my Openshift gear:

<?php 
    require 'php-sdk/facebook.php';
    $facebook = new Facebook(array(
        'appId'  => 'xxxx',
        'secret' => 'xxxx'
    ));
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Facebook PHP</title>
</head>
<body>
<h1>Hello World!</h1>
<?php
    // get user from facebook object
    $user = $facebook->getUser();

    if ($user): // check for existing user id
        echo '<p>User ID: ', $user, '</p>';
    else: // user doesn't exist
        $loginUrl = $facebook->getLoginUrl(array(
            'display' => 'popup',
            'redirect_uri' => 'http://apps.facebook.com/myappname'
        ));
        echo '<p><a href="', $loginUrl, '" target="_top">login</a></p>';
    endif; 
?>
</body>
</html>

What am I doing wrong?

When I enter my Facebook app's URL (http://apps.facebook.com/myappname), Hello World! and my login link is display on top of my Facebook's app's iframe. However when I click on the login link, I get the above mentioned error. Any assistance will be greatly appreciated!

EDIT

I entered the following urls in my browser and Hello World and the login link were both displayed.

http://myappname-mydomainname.rhcloud.com/
https://myappname-mydomainname.rhcloud.com/
Community
  • 1
  • 1
Anthony
  • 3,990
  • 23
  • 68
  • 94
  • 1
    Everything looks fine. But just a shot in the dark: when I compare your configuration to mine, I would say you need to add a slash at the end of `http://myappname-mynamespace.rhcloud.com` as for the Site URL. – Stéphane Bruckert Oct 02 '13 at 09:02
  • +1 Thank you for your reply @StéphaneBruckert I double checked my Site URL and I have a forward slash `http://fbtest-projectkohana.rhcloud.com/`. I'll correct my question. I may have put the `/` after writing this question but it still does not work. This is the second test app I'm writing which had produced this error. Is this problem related to my use of Openshift? Openshift uses shared SSL certificates for free accounts like mine. – Anthony Oct 02 '13 at 12:03
  • 1
    Some time its happen that whatever you make changes in FB settings will affect after some hours. so keep checking once you done changes. – Chandresh M Oct 03 '13 at 05:14
  • +1 yes, I saw that message when I updated my facebook app. But it's been days now. Oh boy @Chandresh this has been a real challenge for me. I suspect it has to do with OpenShift shared SSL certs, I don't know. I'm trying to figure out another cloud provider I can use for free to test this out. – Anthony Oct 03 '13 at 23:53
  • 1
    @anthony I would suggest trying amazon AWS EC2. You need to know linux thought, but its very powerful and they give you a micro instance for free for a year, no obligations. I bet it is related to openshift, they have some funky redirects going on. – Kenny Oct 08 '13 at 23:40

1 Answers1

2

A while back I was tinkering with Facebook's API for whatever reason, I kept on getting the same error. Turns out some urls with http were supposed to be https, not that facebook made a point of leaving correct instructions. I would suggest changing Site URL: http://myappname-mynamespace.rhcloud.com to Site URL: https://myappname-mynamespace.rhcloud.com. If this doesn't help I would suggest looking at the other URLs and changing them. Good Luck

  • +1 Thank you so much for your reply. I changed my site URL (in FB configuration) to `https://fbtest-projectkohana.rhcloud.com/` saved it, then refreshed but I got the same error. However in the url of my browser, I noticed that the redirect uri had http, not https `...redirect_uri=http%3A%2F%2F...`. I changed the above mentioned script to use https instead and git pushed it to the Openshift server successfully and now I'm seeing `...redirect_uri=https%3A%2F%2F...` but I'm still getting the same error. Is this error caused by the shared ssl certificate my free Openshift account/app uses? – Anthony Oct 02 '13 at 12:29