ether
ether

Reputation: 937

Facebook API error 191 Invalid redirect_uri (not on localhost)

Yes, another API error 191 question.

So, I have an app that I use in a page tab.
I have 2 different DNS for my page: one for http (cime.fm) and one for https (securecdi.com).
On my authentication page, I make sure that I redirect to the http or https server, so it looks like this:

if($_SERVER['HTTP_HOST'] == 'dev.securecdi.com' || $_SERVER['HTTP_HOST'] == 'www.securecdi.com'){
    $http = 'https://';
}else{
    $http = 'http://';
}
$pageTabUrl = $http.'www.facebook.com/cime.fm/app_'.$appId; 
window.top.location.href = "http://www.facebook.com/dialog/oauth?client_id=<?php echo $appId;?>&locale=fr_CA&origin=1&redirect_uri=<?php echo $pageTabUrl;?>&response_type=token%2Csigned_request&scope=publish_stream%2Cuser_likes&sdk=joey";

In facebook's documentation, for redirect_uri, it says:

The URL to redirect to after the user clicks a button in the dialog. The URL you specify must be a URL of with the same Base Domain as specified in your app's settings, a Canvas URL of the form https://apps.facebook.com/YOUR_APP_NAMESPACE or a Page Tab URL of the form https://www.facebook.com/PAGE_USERNAME/app_YOUR_APP_ID

So I have a valid entry for redirect_uri.

In the configuration of my application, I put cime.fm and securecdi.com in the App domains. (I even tried putting facebook.com... but it doesn't change anything)

And most of all, I've done this call with other sites on the same servers (with a DNS for http and another for https) and everything works fine...

Any ideas??

I thought it could be because of the . in the username, but it's not the case since I got the error with yet another website...

examples of what works and what doesn't:

I have a page tab with   
Page Tab URL: http://www.rythmefm.com/montreal/$linkToMyPage 
Secure Page Tab URL: https://www.securecdi.com/rythmefm/montreal/$linkToMyPage   
App Domains: rythmefm.com and securecdi.com   
Redirects to: http://www.facebook.com/pages/1057-rythme-FM/124140938458?sk=app_$appId;  
--> works.

But a page tab with
Page Tab URL: http://www.cime.fm/$linkToMyPage
Secure Page Tab URL: https://www.securecdi.com/cimefm/$linkToMyPage
App Domains: cime.fm and securecdi.com  
Redirects to: http://www.facebook.com/cime.fm/app_$appId;  
--> does not work.

And a page tab with 
Page Tab URL: http://www.fm93.com/$linkToMyPage 
Secure Page Tab URL: https://www.securecdi.com/fm93/$linkToMyPage  
App Domains: fm93.com and securecdi.com  
Redirects to: http://www.facebook.com/fm93/app_$appId;  
--> does not work.

Upvotes: 1

Views: 1302

Answers (1)

ether
ether

Reputation: 937

I found it! Even though Facebook states in the documentation that you can redirect to a page tab with a url of the form: https://www.facebook.com/PAGE_USERNAME/app_YOUR_APP_ID, it's actually not true.

You must use the url of the form:
https://www.facebook.com/pages/PAGE_NAME/PAGE_ID?sk=app_YOUR_APP_ID;
which is the form of pages without a username set.

Upvotes: 1

Related Questions