I’ve recently had feedback from one or two “Facebook Application Development” course students who’ve ran into the infamous “error 191″ problem when trying to run their Facebook Apps.
Normally this error is caused by using an incorrect URL in the ‘redirect_uri’ parameter for getLoginUrl when using the PHP SDK, for example:
$loginUrl = $facebook->getLoginUrl(array('scope'=> 'user_checkins','redirect_uri'=> $app_url));
Another potential cause of this error is mixing your http: and https: URLs or assigning a http: URL to this parameter when the user is actually using a secure https: URL to access your App.
When I recorded the Facebook course the need to check the protocol and assign the correct http: or https: URL simply wasn’t there. Now we need to do this. Many users have switched over to using Facebook over a secure connection and Facebook will also switch off support for http:-only Apps anytime soon (as usual, no exact date).
Here’s a little snippet you can use to check for the protocol being used and assign the ‘redirect_uri’ correctly:
$protocol = ($_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
Then simply prepend $protocol to your ‘apps.facebook.com/…’ string to form the URL.
If that’s not the issue and all seems to be fine, all URLs look right and you simply can’t see what else could be wrong, then don’t panic: Stop pulling your hair out
Have you set up an App Namespace in the Developer App?
It turns out that, if you don’t set this and use the APP NAMESPACE to refer to the App, you can get the dreaded 191 error. Set it and use it in your redirect_uri instead of the FB-generated App ID number.
When I recorded the course, the App Namespace was generated and used by default to reference the App. Hence the problem didn’t arise. This is one of the things that have changed since the course was recorded.
- Check that your URLs and protocols match – both in the Developer App and in your code.
- Assign the correct protocol when assigning the ‘redirect_uri’ parameter for getLoginUrl().
- Use the App Namespace and not the App ID to reference your App on apps.facebook.com
There have, of course, been many more changes in the World of Facebook App Dev since I recored the course – even since it’s release. Watch this space for more updates over the next few weeks!
Happy Facebook App-building!