Facebook API error 191
Asked Answered
B

11

77

I'm trying to integrate my project with Facebook. I'm taking baby steps at first and just trying to login, get a Facebook session, and get some user data. I'm developing it locally so my Facebook application settings are:

site URL: http://127.0.0.1:8888/mySite/

The canvas URL is the same as above. I haven't specified a site domain.

However, when I click on the login button, I get an error:

API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: redirect_uri is not owned by the application.

At the moment I haven't written any server-side code to deal with redirects, etc. All I've done is add the JavaScript SDK based on the tutorial in Facebook for Websites.

What have I done wrong? It's obviously something to do with my Facebook application settings, but I can't see what!

Bulk answered 14/1, 2011 at 13:56 Comment(1)
For readers: please notice that this question and the accepted answer apply both to local server & development/testing, and real servers and urls!Acquittal
B
89

UPDATE:
To answer the API Error Code: 191
The redirect_uri should be equal (or relative) to the Site URL.
enter image description here

Tip: Use base URLs instead of full URLs pointing to specific pages.

NOT RECOMMENDED: For example, if you use www.mydomain.com/fb/test.html as your Site URL and having www.mydomain.com/fb/secondPage.html as redirect_uri this will give you the 191 error.

RECOMMENDED: So instead have your Site URL set to a base URL like: www.mydomain.com/ OR www.mydomain.com/fb/.


I went through the Facebook Python sample application today, and I was shocked it was stating clearly that you can use http://localhost:8080/ as Site URL if you are developing locally:

Configure the Site URL, and point it to your Web Server. If you're developing locally, you can use http://localhost:8080/

While I was sure you can't do that, based on my own experience (very old test though) it seems that you actually CAN test your Facebook application locally!

So I picked up an old application of mine and edited its name, Site URL and Canvas URL: Site URL: http://localhost:80/fblocal/

I downloaded the latest Facebook PHP-SDK and threw it in my xampp/htdocs/fblocal/ folder.

But I got the same error as yours! I noticed that XAMPP is doing an automatic redirection to http://localhost/fblocal/ so I changed the setting to simply http://localhost/fblocal/ and the error was gone BUT I had to remove the application (from privacy settings) and re-install my application and here are the results:
alt text

After that, asked for the publish_stream permission, and I was able to publish to my profile (using the PHP-SDK):

$user = $facebook->getUser();
if ($user) {
    try {
        $post = $facebook->api('/me/feed', 'post', array('message'=>'Hello World, from localhost!'));
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}

Results: alt text

Belinda answered 14/1, 2011 at 14:2 Comment(6)
Um, so now I'm confused. What about this answer: https://mcmap.net/q/266565/-facebook-app-developmentBulk
I GUESS what he meant is that you can test your application locally, but any interaction with facebook will require publishing your website/domain. for example if you have a flash game, you can test it locally before through it on FB canvas. As for the code after that, he is explaining how you can protect your live website from being access until the development is finished and you are ready to go live.Belinda
So far so good! I've got as far as the login dialog and asking for permissions! I haven't had a chance to test grabbing some actual data yet, but look forward to the answer being accepted when I do! Woohoo!Bulk
how did you reinstall the app? I am in Sandbx Mode and getting same 191 error unless I access my redirect_url directly on browser which then shows me Auth DialogSalmagundi
@Volatil3, I just removed it from my app list in the privacy settings.Belinda
Configure the Site URL, and point it to your Web Server. If you're developing locally, you can use http://localhost:8080/ It shows error, because it wants not localhost, but 127.0.0.1Bolivar
G
11

For me, it was a missing app domain. Go into the app, and make sure that you have the root of your site set up as an app domain. See screenshot.

app domains is in the basic settings of your app

Garrik answered 23/5, 2013 at 16:47 Comment(2)
This answer is not related to the question since the original poster is developing locally and the App Domains field doesn't allow either localhost or 127.0.0.1 : flic.kr/p/kHqinyWhiteman
The asker's question is already resolved. This answer is intended to be useful to people with a similar problem, who think that this question will help them based on the big bold title. Now it can.Garrik
D
8

This is just because of a URL mistake.

Whatever website URL is specified should be correct.

I mentioned website URL as http://localhost:3000/ and domain as localhost, but in my browser I was running http://0.0.0.0:3000/.

When I ran server as localhost:3000 it solved the problem.

As I mentioned, the site URL as localhost Facebook will redirect to the same, if we are running 0.0.0.0:3000, it will rise error that "Given URL is not allowed by the Application configuration".

Deform answered 30/4, 2012 at 8:20 Comment(0)
G
2

I was also facing the same problem when I am using the facebook authentication method. But I rectify that issue with following changes in Facebook api (Apps >> My App >> Basic).

  1. I removed the url which i have given in ===> App on Facebook (Canvas URLs)
  2. I gave site url only in ===> Website with Facebook Login option

Then i gave that AppId and App Secret in my webpage.

So by clicking on login button, It ask for access permissions then it redirect it to give url (Website with Facebook Login ).

Garey answered 10/9, 2012 at 12:25 Comment(0)
P
1

I fixed this by passing the redirect url to the FacebookRedirectLoginHelper::getAccessToken() in my callback function:

Changing from

try {
        $accessToken = $helper->getAccessToken();
}
...

to

try {
        $accessToken = $helper->getAccessToken($fbRedirectUrl);
}
...

I am developing on a vagrant box, and it seems FacebookRedirectLoginHelper::getCurrentUrl() had issues generating a valid url.

Preestablish answered 11/6, 2018 at 9:40 Comment(0)
A
0

Had the same problem:

$params = array('redirect_uri' => 'facebook.com/pages/foobar-dev');
$facebook->getLoginUrl($params);

When I changed the redirect_uri from the devloper page to the live page, 191 Error came up.

So I deleted the $params:

$facebook->getLoginUrl();

After the app-request now FB redirects to the app url itself f.e.: my.domain.com

What I do now is checking in index.php of my app if I'm inside FB iframe or not. If not I redirect to the live FB page f.e.:

$app = 'facebook.com/pages/foobar-live';
$rd = (isset($_SERVER['HTTP_REFERER'])) ? parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) : false;
if ($rd == 'apps.facebook.com' || (!isset($_REQUEST['signed_request'])))  {
    echo '<script>window.parent.location = "'.$app.'";</script>';
    die();
}
Annamarieannamese answered 21/11, 2012 at 17:22 Comment(0)
B
0

I have noticed also that even if you specify your website under secion - Website With Facebook Login -> Site url as e.g. http://example.com, but if your App Domains section is empty, and you open website as www.example.com you will get this error, too. To avoid it in "App Domains" section write example.com, that will allow subdomains, like www.example.com, something.example.com etc

Braddy answered 5/12, 2012 at 13:42 Comment(0)
E
0

in the facebook App Page, goto the basic tab. find "Website with Facebook Login" Option.

you will find Site URL: input there put the full URL ( for example http://Mywebsite.com/MyLogin.aspx ). this is the URL you can use with the call like If the APP ID is 123456789

https://graph.facebook.com/oauth/authorize?client_id=123456789&redirect_uri=http://Mywebsite/MyLogin.aspx&scope=publish_actions

Eubank answered 28/6, 2013 at 19:47 Comment(0)
I
0

Something I'd like to add, since this is error 191 first question on google:

When redirecting to facebook instead of your own site for a signed request, you might experience this error if the user has secure browsing on and your app does redirect to facebook without SSL.

Intermeddle answered 5/12, 2013 at 16:15 Comment(0)
P
0

Working locally... I couldn't get the feeds api to work, but the share api worked pretty much straight away with no problems.

Pitching answered 8/9, 2015 at 9:44 Comment(0)
P
0

For me it's the Valid OAuth Redirect URIs in Facebook Login Settings. The 191 error is gone once I updated the correct redirect URI.

enter image description here

Phonemic answered 16/10, 2020 at 4:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.