[eluser]cheungj[/eluser]
Hey all,
So recently I discovered that I was able to log into Facebook using CI.
I wanted to ensure that this was working with different phones, and fortunately, I had access to a multitude of different devices.
I just want to mention how I fixed it because I couldn't find any information that related to this.
I was initially testing the login with a Samsung Galaxy S Plus. Everything worked fine there.
Then, I tried to log in using an iPhone 4s -- it failed with the dreaded error message:
Code:
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.
I spent a while trying to fix this.
1.
First, turn on the error display to debug:
Code:
$loginUrl = $facebook->getLoginUrl(array(
'show_error' => true));
2.
Second, as most Q/A answers will mention, ensure that within your App's Facebook settings, turn the sandbox mode
off if you are testing live.
Now for the problem I came across. It was related to the Site URL field in the Facebook App settings. I had it set to 'https://www.subdomain.domain.ie/index.php'. Bear in mind that I was able to log in using any URL with the prior URL + the CI function name.
Here was the little problem; Any URL I attempted to log in with that didn't contain the 'www', failed. So for example, logging into Facebook from 'https://subdomain.domain.ie/index.php/test.php', failed. Facebook doesn't corrct anything for you, so I had to change my php code.
Here was my solution: I changed the Site Url in Facebook to 'https://subdomain.domain.ie/index.php' (without the 'www'). Then, at the beginning of each controller function, I checked the URL for the 'www', and if it was there, I removed it, and redirected to the page without 'www'.
My code at the beginning of each function was:
Code:
if(strstr(current_url(), 'www.')) {
$controller_url = $this->uri->uri_string();
$full_url = site_url($controller_url);
$full_url = str_replace('www.', '', $full_url);
redirect($full_url);
}
I hope this helps somebody else.
TL;DR: Facebook cares if your App's site URL begins with 'www' or doesn't.