Reputation: 3998
When a user accesses my facebook app via http://apps.facebook.com/myappxxxxx, I want it to immediately show the request permissions fb dialog - like so many others do.
I have tried all sorts of things - including php redirect using the getLoginUrl, javascript window location redirect using the same.
The problem is that it shows a big facebook icon instead of the request permissions. However, if you click on that icon, it in fact goes to the correct request permissions page!
Does anyone know how to redirect to the facebook permissions page properly?
I am using the PHP api and JavaScript SDK with an iFrame FB app.
Upvotes: 8
Views: 15898
Reputation: 11
When I change the url as below, it worked !!!!!
if(!$me) {
$url = "https://www.facebook.com/dialog/oauth?"
."client_id=YOUR_APP_ID&"
."redirect_uri=http://apps.facebook.com/APP_SLUG/&"
."scope=user_photos,publish_stream";
echo "<script language=javascript>window.open('$url', '_parent', '')</script>";
} else {
your code...
}
Thanks for the post
Upvotes: 0
Reputation: 4654
I had the exact same problem a while ago. Here's a little hack:
if(!$me) {
$url = "https://graph.facebook.com/oauth/authorize?"
."client_id=YOUR_APP_ID&"
."redirect_uri=http://apps.facebook.com/APP_SLUG/&"
."scope=user_photos,publish_stream";
echo "<script language=javascript>window.open('$url', '_parent', '')</script>";
} else {
your code...
}
How it looks in my code (a bit dirty, I had a deadline):
require_once 'facebook-php-sdk/src/facebook.php';
$appid = '';
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => '',
'cookie' => true,
));
$session = $facebook->getSession();
$me = null;
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
if(!$me) {
// here we redirect for authentication:
// This is the code you should be looking at:
$url = "https://graph.facebook.com/oauth/authorize?"
."client_id=$appid&"
."redirect_uri=http://apps.facebook.com/APP_SLUG/&"
."scope=user_photos,publish_stream";
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>Göngum til góðs</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<script language=javascript>window.open('<?php echo $url ?>', '_parent', '')</script>
</head>
<body>
Loading...
</body>
</html>
<?php
exit;
} else {
your code ...
}
A simple header redirect won't work since it will only redirect your iframe. Javascript is needed to access the _parent window.
Keep in mind that there is a proper way to do this (see answer below) and I do not recommend doing this. But hey, what ever floats your boat...
Upvotes: 8
Reputation: 5170
Why don't you try the Facebook authenticated referrals? It's the proper solution for such problem. Since it asks Facebook to traps the non-connected users and redirect them directly to the connect page.
This insure that all of the users are connected to your app by default.
Upvotes: 5
Reputation: 1430
The url should be from getLoginUrl($PARAMS). It worked for me. In your case,
$PARAMS = array('scope' => 'user_photos,publish_stream',
redirect_uri => 'https://apps.facebook.com/myappxxxxx');
Upvotes: 1
Reputation: 57612
Here's another option:
<script>
(function () {
var url = 'your_permission_url';
window.top.location.href = url;
} ());
</script>
Upvotes: 2