I've got an iframe loading in a facebook tab on a fan page and I'm not having any luck accessing the $_REQUEST["signed_request"] object. I'm confused because this is supposed to be a freebie and easily accessible. I've read and re-read the facebook docs and rechecked my facebook application settings but nothing is working.
isset($_REQUEST['signed_request']
is always false. Since I'm using the Facebook PHP sdk I've also tried
$facebook->getSignedRequest();
I've done print_r on the $_REQUEST and I don't see the signed_request in there. When I print_f the $facebook object, I see that the signedRequest is empty
[appId:protected] => XXX
[apiSecret:protected] => XXXXXXXXXXXXXXXXXXXX
[session:protected] => Array
[access_token] => XXXXXXXXXX|2.h75WqKxcA1xbNPufFvpKQQ__.3600.1304452800.1-726960374|JiO0ZS30SyLaApeqhMtdocK8B_Y
[base_domain] => XXXXXXXXX
[expires] => 1304452800
[secret] => rDF9C_z43_EUFy0Q_e6tyQ__
[session_key] => 2.h75WqKxcA1xbNPufFvpKQQ__.3600.1304452800.1-726960374
[sig] => 1971ef7eb8057c7404eae1f82d770ab5
[uid] => XXXXXXXXXXXXXXX
[signedRequest:protected] =>
[sessionLoaded:protected] => 1
[cookieSupport:protected] => 1
[baseDomain:protected] =>
[fileUploadSupport:protected] =>
[EDIT]
I do have the OAuth 2.0 setting enabled for the application.
OK, just had this on problem myself and found the issue.
Make sure that you do not have a 301 redirect on the canvas or tab page. In my case I set the app up as "mydomain.com/facebook/tab/" but my site was doing a 301 to "www.mydomain.com/facebook/tab/"
The content would show, bit the 301 caused the signedRequest to be null.
Added "www" to my domain in the app settings and the signedRequest now contains the data I was looking for.
I just had this problem. Finally figured it out. I had to add a forward slash to the end of my Tab URLs in the application settings on the Basic tab.
Instead of:
http://domain.com/facebook
I needed:
http://domain.com/facebook/
I had the same problem And I resolve it.
It's a problem with the URLS. Be sure that your
App Domain & Page Tab URL match the same domain for example:
1) App domain: example.com
Page Tab URL: example.com
will work
2) App domain: example.com
Page Tab URL: example.com/app/
will work
3) App domain: fb.example.com
Page Tab URL: fb.example.com/app/
will work
4) App domain: fb.example.com
Page Tab URL: example.com/fb
will not work
After some investigation, I suspect this has something to do with where the iframe source is hosted.
When I moved everything to localhost, the signed_request started coming in fine.
Edit the settings of your tab application.
On "Advanced" tab, make sure "OAuth 2.0 for Canvas" is enabled.
it's an old question but I found this with google...
the problem for me was that I did a manual redirect to the https url of my pagetab and than the $_POST['signed_request'] got lost
Related
I would like to add facebook login option to my website, following this tutorial. I did everything as it is in the tutorial, but I still get this error:
OAuthException: redirect_uri isn't an absolute URI
How is it possible to solve it?
This urls are generated by the facebookOAuthProvider. The website is not on localhost. It runs on a webserver, with https.
This is the relevant code:
// redirect to Facebook
$facebookOAuthProvider = $this->get('app.facebook_provider');
$url = $facebookOAuthProvider->getAuthorizationUrl([
// these are actually the default scopes
'scopes' => ['public_profile', 'email'],
]);
return $this->redirect($url);
It redirects to this url:
https://www.facebook.com/v2.3/dialog/oauth?scopes[0]=public_profile&scopes[1]=email&state=...&scope=public_profile,email&response_type=code&approval_prompt=auto&redirect_uri=/connect/facebook-check&client_id=...
The redirect_uri is indeed not an absolute url. But how is it possible to fix it?
Edit
If I add 'redirect_uri' => [$redir] then the url looks like this:
https://www.facebook.com/v2.3/dialog/oauth?scopes%5B0%5D=public_profile&scopes%5B1%5D=email&scopes%5B2%5D=user_location&redirect_uri%5B0%5D=https%3A%2F%2Fexample.com%2Fconnect%2Ffacebook-check&state=...&scope=public_profile%2Cemail&response_type=code&approval_prompt=auto&client_id=...
I can see the absolute redirect_uri in the generated url, but I still get this error, if I navigate to it
Redir is defined as:
$redir = $this->generateUrl('connect_facebook_check', array(), UrlGeneratorInterface::ABSOLUTE_URL);
Edit2
If I replace [$redir] with $redir then facebook redirects me correctly to /connect/facebook-check with a code, but I get a OAuthException: redirect_uri isn't an absolute URI. Check RFC 3986 there.
I don't know where you got the example code, but certainly not from the linked tutorial.
Facebook authorization is based on the fact that you generate a link to FB, the user goes to the FB and authorizes himself, and then the FB server redirects it back to you (along with whether or not it is authorized).
FB does not guess where to redirect user after login. You need to give him a full path with http(s) and the server name (and if I remember correctly, it is also compatible with that saved in the FB app)
The attached tutorial requires writing a controller with 2 methods (output and return) and corresponding entries in the configuration.
If you use this, then see how you have configured the provider. What is in redirectUri?
I am getting this error:
Given URL is not allowed by the Application configuration: One or more of
the given URLs is not allowed by the App's settings. It must match the
Website URL or Canvas URL, or the domain must be a subdomain of one of the
App's domains.
This is how i set my website url:
Why is my url wrong ? Can someone explain me this part ? thx
UPDATE
I tried the following combination:
http://attila-naghi.com/facebook/mytest/
http://attila-naghi.com/facebook/mytest
http://attila-naghi.com/facebook/mytest/index.php
http://www.attila-naghi.com/facebook/mytest/
http://www.attila-naghi.com/facebook/mytest
http://www.attila-naghi.com/facebook/mytest/index.php
but I still get the error.
The error appeared because I did not pass the 'redirect_uri' correctly. I missed the ".com" part. So it should look like this:
$loginUrl = $facebook->getLoginUrl(array (
'scope' => 'publish_actions,read_stream,user_groups,user_about_me,user_interests',
'redirect_uri' => 'http://attila-naghi.com/facebook/mytest/test.php'
));
and
'Given URL is not permitted by the Application configuration: One or more of the given URLs is not allowed by the App's settings. To use this URL you must enable Web OAuth Login in your App's settings.'
error message appeared because it must set the Web OAuth Login to yes and I must add an url for the Valid OAuth redirect URIs field
I have integrated a e-commerce site in my facebook fan page via page tab
https://www.facebook.com/Thesoftwareguy7/app_687345671301257
the problem it I want too append some custom url to it
https://www.facebook.com/Thesoftwareguy7/app_687345671301257?f=1
but when I parse the URL it gives me
Array ( [scheme] => https [host] => s-static.ak.facebook.com [path] => /platform/page_proxy/hv09mZVdEP8.js )
It worked perfectly in facebook apps when i append it in apps.facebook.com/687345671301257/
But it does not work in facebook fanpage custom tab.
Thanks for your time?
Did you have a look at the app_data field in the signed_request? The docs are here: https://developers.facebook.com/docs/appsonfacebook/pagetabs/#integrating
This would result in a Page Tab URL of https://www.facebook.com/Thesoftwareguy7/app_687345671301257?app_data=f%3D1
You then have to decode the app_data parameter to get the key/value.
I have the Restful settings enabled on the settings page and I have create a user with access keys.
I am using the PHP library and im getting this reponse.
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[code] => 404
[message] => cURL HTTP error 404
)
)
)
If i visit the url in the browser /wc-api/v1 I also get a 404 response. I have seen some mentions of changing Permalink structure but it doesn't say what too anywhere?
Any pointers? Greatly received :)
Ok so they settings I need were...
Post name http://www.dipdye.co.uk/sample-post/
and
Shop base with category http://www.dipdye.co.uk/shop/product-category/sample-product/
After further reading it seems any 'pretty' url will work, my main issue was it not updating my Web.config file (as Im on IIS) on Apache this would be the .htaccess file.
I can now see something when i visit the page in web browser.
Hope this help someone else too.
Please, I need help. I'm dealing with this issue for 1 month!!
I would like to implement facebook connect login to my website, using PHP and php-sdk 3.1.1. In few words, my code works offline (on localhost) but not online which results in "Too many redirect loop (on Chrome)": Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.
Here is my code:
1/ I load facebook connect SDK and init it:
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => '209633612480053',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
));
Please, note that I created two apps on facebook-developper page, one for offline tests, and the other for online tests. And I'm sure to switch correctly betwwen the two pairs of appId/secret (online and offline) when testing. So it's not the problem of bad facebbok-connect init.
2/ I try to get user info:
$uid = $facebook->getUser();
if($uid)
{
/*
* Get user information.
*/
$user = $facebook->api('me/');
print_r($user); // Display user info.
}
else
{
/*
* Redirect to FB login URL to allow access.
*/
$loginURL = $facebook->getLoginURL();
echo '<script> top.location.href=\''.$loginURL.'\'</script>';
}
It's as simple as that: If user ic connected to facebook, so display it's information, else, redirect to facebook login page to allow access.
IT WORKS PERFECTLY OFFLINE, but online, I get a chrome error:
This webpage has a redirect loop
The webpage at https://www.facebook.com/dialog/oauth?client_id=209633612480053&redirect_uri=http%3A%2F%2Fwww.bluward.com%2Foauth%2Ffacebook&state=551f60cd4be6cd8ed1622f8168a5219a#_=_ has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
Some additional information: Online, I use 1and1 host provider, and to be sure to have the same server configuration than offline server (which is a MAMP Pro), I uploaded the sams php.ini file.
Please, if someone has an idea, or get a similar problem, I'll be glad to have help.
Thank you in advance for all help.
UPDATE:
I updated my code to focus on the problematic line, so instead of redirecting to facebook login page, I display the redirect URL, so I just have to click to login:
$uid = $facebook->getUser();
if($uid)
{
/*
* Get user information.
*/
$user = $facebook->api('me/');
print_r($user); // Display user info.
}
else
{
/*
* Redirect to FB login URL to allow access.
*/
$loginURL = $facebook->getLoginURL();
echo $loginURL; // <-- HERE I CHANGED THE CODE TO DISPLAY LOGIN URL
}
What I noticed is that facebook is infinitely redirecting to my script page. Only code parameter on URL bar changes.
So, why facebbok is redirecting to my script page without giving me user info?
Please, any idea?
I had this problem, in my case I had to edit base_facebook.php from the SDK:
public static $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php-3.2',
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
);
The last two options I added manually.
I had a similar issue with chrome browser, cookies always were incorrect or empty.
Then I downloaded a facebook example from Heroku (it uses a popup window as login instead of a js redirect) and noticed that it doesn't work in chrome when the base URL of the website isn't the server root URL (ex: localhost/somedirectory/).
But after creating a virtual host it looks like it works.
You can see an example of the index.php from the application here https://gist.github.com/2845986