开发者

Facebook require_login() in iFrame App

开发者 https://www.devze.com 2022-12-24 06:42 出处:网络
I have serious problem with iframe application. I need to use many external JS libraries and other dynamic stuuf so FMBL application can\'t be done. When I call require_login() I get applicaition inst

I have serious problem with iframe application. I need to use many external JS libraries and other dynamic stuuf so FMBL application can't be done. When I call require_login() I get applicaition installing dialog when app is not already installed, which is ok. But then after authorization application enters an endless redirect loop with parameters like auth_token, installed and so. Yesterday I managed to fix this, but today it's broken again... What the heck is happening with FB? It's driving me crazy to find a sollution, none of ones found on net doesn't seem to be working.

So far I tried:

http://abhir开发者_如何学编程ama.wordpress.com/2010/03/07/facebook-iframe-xfbml-app/ (7th march 2010!) http://forum.developers.facebook.com/viewtopic.php?pid=156092 http://www.keywordintellect.com/facebook-development/how-to-set-up-a-facebook-iframe-application-in-php-in-5-minutes/

http://www.markdeepwell.com/2010/02/validating-a-facebook-session-within-an-iframe/ http://forum.developers.facebook.com/viewtopic.php?pid=210449 http://www.ajaxlines.com/ajax/stuff/article/facebook_fbml_rendering_in_iframe_application.php http://www.aratide.com/php/solving-the-break-out-issue-in-iframe-facebook-applications/

None of the above worked... According to those and some FB docs: http://wiki.developers.facebook.com/index.php/FB_RequireFeatures http://wiki.developers.facebook.com/index.php/Cross_Domain_Communication_Channel

My example test files look as follow:

<?php
//Link in library.
require_once '../application/vendor/Facebook/facebook.php';

//Authentication Keys
$appapikey = 'XXXX';
$appsecret = 'XXXX';

//Construct the class
$facebook = new Facebook($appapikey, $appsecret);

//Require login
$user_id = $facebook->require_login();

?>

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
  <title></title>
</head>
<body>
  <script src="http://static.ak.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
  This is you: <fb:name uid="<?php echo  $user_id?>"></fb:name>
  <?php var_dump($facebook->$this->facebook->api_client->friends_get())?>
  <script type="text/javascript">
 FB_RequireFeatures(["XFBML"], function(){
  FB.Facebook.init("<?=$appapikey?>", "xd_receiver.html");
 });
  </script>
</body>
</html>

And cross-domain file xd_receiver.html is:

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>cross-domain receiver page</title>
  </head>
  <body>
    <script src="http://static.ak.facebook.com/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script>
  </body>
</html>

How do I get it working?

I'm using Kohana framework to do this and already replaced header('Location') with url::redirect() in facebook php library.


A lot of the tutorials you're looking at are very out-of-date. The Facebook API and accompanying SDKs change fairly rapidly, and while that doesn't mean it's not possible to do things in the "old" ways, those ways are more likely to be broken, deprecated, removed, or less well-documented.

For better support try upgrading to the latest PHP SDK: https://github.com/facebook/php-sdk/

Then you can use this example as a base for what you're trying to do: https://github.com/facebook/php-sdk/blob/master/examples/example.php

It presents the user with a login link, but if you're in a context where you want to force login, showing content only to logged-in users (imitating old require_login), you could replace:

// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}

with:

// Get logout URL, or redirect user to login URL
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  header('Location: ' . $facebook->getLoginUrl()) ;
}


Facebook restricts the usage of many HTML tags. It seems that you are using some of the restricted tags in your code. Have you tried removing those?

In case you want to use those tags (<body> for e.g.) make it an iframe application instead of fbml...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号