2010-03-29 98 views
0

我有iframe应用程序的严重问题。我需要使用许多外部JS库和其他动态stuuf,因此FMBL应用程序无法完成。当我调用require_login()时,当应用程序尚未安装时,我得到了应用程序安装对话框,这没关系。但是,然后在授权应用程序进入无尽的重定向循环,如auth_token,安装等参数。昨天我设法解决了这个问题,但今天它又被打破了...... FB发生了什么事情?这让我疯狂找到一种溶剂,在网上发现的任何一种都没有效果。Facebook的require_login()在iFrame应用程序

到目前为止,我尝试:

http://abhirama.wordpress.com/2010/03/07/facebook-iframe-xfbml-app/(!2010年3月7日) 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/

无上述工作......根据这些和一些FB文档: http://wiki.developers.facebook.com/index.php/FB_RequireFeatures http://wiki.developers.facebook.com/index.php/Cross_Domain_Communication_Channel

我的示例测试文件看起来如下:

<?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> 

和跨域文件xd_receiver.html是:

<!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> 

我如何得到它的工作?

我正在使用Kohana框架来做到这一点,并已在facebook php库中用url :: redirect()替换了header('Location')。

回答

0

Facebook限制了许多HTML标签的使用。看起来你在代码中使用了一些受限制的标签。你有没有尝试删除这些?

如果你想使用这些标签(<body>用于例如)使它成为一个iframe的应用程序而不是FBML ...

+0

这是一个iframe应用程序。我尝试在iframe中调用require_login,并将我的服务器上的Facebook外部重定向到应用程序,并以URI中auth_token变量的无限循环结束。我也尝试了FBML应用程序,并使用将iframe放入画布中,但流程相同。 – 2010-04-04 10:08:28

1

很多你看教程都非常出过期。 Facebook API和随附的SDK变化相当迅速,尽管这并不意味着以“旧”方式做事情是不可能的,但这些方式更可能被破坏,弃用,删除或记录不足。

为了更好地支撑尝试升级到最新的PHP SDK:https://github.com/facebook/php-sdk/

然后你就可以用这个例子作为基础对你正在试图做什么: ​​

它提出一个用户登录链接,但如果你在哪里,你要强迫登录背景下,只显示已登录的用户(模仿旧require_login),你可以替换的内容:

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

机智h:

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