0

Possible Duplicate:
Facebook API error 191

I am getting the following error with some code that I am using. The error is

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.

<?php   
$facebook = new Facebook(array('appId' => $app_id,'secret' => $app_secret,'cookie' => true));
if($facebook->getUser() < 1)
{
    $red_url = $page_url.'?sk=app_'.$app_id;
    $redir = $facebook->getLoginUrl(array('redirect_uri'=>$red_url,'next'=>$red_url,'scope'=>'offline_access,publish_stream,status_update,photo_upload,user_birthday'));
    echo "<script>top.location.href='".$redir."';</script>";
    exit;
}
$user = $facebook->api('/me');

Can any one explain how to get around this and why this happens?

Community
  • 1
  • 1
Bal 3D
  • 5
  • 2
  • 1
    The error seems quite obvious. You're using a redirection url that doesn't match the given domain names in your application settings. – Ja͢ck Jan 19 '13 at 22:51

3 Answers3

0

Can you say "cross site scripting" ;)?

WORKAROUND:

Browser, Edit Setting, Web Site <= add site URL to the app settings

Here's a bit more background:

* http://techblog.hybris.com/2012/06/05/oauth2-the-implicit-flow-aka-as-the-client-side-flow/

redirect_uri: The server configured a redirect_uri (which we strongly recommend) which needs to match the settings for the client_id. Client_id and redirect_uri are both server-side settings that the app developer needs to get at beforehand.

paulsm4
  • 114,292
  • 17
  • 138
  • 190
0

You need to tell Facebook that your app is allowed access to that website.

Edit your app settings (via the FB developer dashboard). On the basic settings page, click on 'Website with Facebook Login' and enter your site address.

Editing your Facebook app websites

Adam Hopkinson
  • 28,281
  • 7
  • 65
  • 99
0

When you open a Facebook application you need to set the domain/s under which your application is intended to run - and (almost) every place that your app gets in contact with facebook (especially client side) must be from a url from the same domain (or a subdomain of it)

in your case you told asked facebook to authorize the app for the user and then redirect him to $red_url which I understand to be the page where your app is installed - BUT this link is not under the domain of your application (unless you registered facebook.com as your app domain in the application dashboard

if you want to redirect the user to that specific tab - you may create a proxy file under the domain of your application that will redirect the user to the tab, for example:

lets say you registered mydomain.com as your app domain in the app dashboard . then - create a file named redirect.php for example that will conatin the following script and put it under http://www.mydomain.com/my_directory/redirect.php :

<?php
$app_id ="ENTER_YOUR_APP_ID_HERE";
$page_url = "ENTER_THE_PAGE_URL_HERE"; //for example: http://www.facebook.com/techmarketing.co.il
$red_url = $page_url.'?sk=app_'.$app_id;

header("Location: {$red_url}");

and your script will change to be:

<?php   
$facebook = new Facebook(array('appId' => $app_id,'secret' => $app_secret,'cookie' => true));
if($facebook->getUser()==0)
{
    $red_url = "http://www.mydomain.com/my_directory/redirect.php";
    $redir = $facebook->getLoginUrl(array('redirect_uri'=>$red_url,'next'=>$red_url,'scope'=>'offline_access,publish_stream,status_update,photo_upload,user_birthday'));
    echo "<script>top.location.href='".$redir."';</script>";
    exit;
}
$user = $facebook->api('/me');
Yaron U.
  • 7,681
  • 3
  • 31
  • 45