问题描述
我已将从FBML转换为iFrame(使用PHP SDK)现在有垂直滚动条显示我之前相同的内容(徽标,Flash游戏和下面3个链接的行)。但是早些时候我没有任何滚动条。
I've converted a Facebook app from FBML to iFrame (with PHP SDK) and now have vertical scrollbars displayed for the same amount of content I had before (a logo, a flash game and a line with 3 links below). But earlier I didn't have any scrollbars.
如果我设置应用程序设置自动调整大小,那么内容的下半部分根本不会显示 - 这是糟糕的是,Flash游戏无法播放。
If I set the app setting Auto-Resize, then the lower part of content isn't displayed at all - which is bad, the flash game is unplayable then.
我一直在搜索,所有建议的解决方案都涉及Javascript,但我实际上是在使用PHP SDK。是不是只有PHP / CSS的解决方案?
I've searched around and all suggested solutions involve Javascript, but I'm actually using PHP SDK. Isn't there a solution for PHP/CSS only?
在我当前的代码下面:
<?php
require_once('facebook.php');
define('FB_API_ID', 'XXX');
define('FB_AUTH_SECRET', 'XXX');
$facebook = new Facebook(array(
'appId' => FB_API_ID,
'secret' => FB_AUTH_SECRET,
'cookie' => true,
));
if (! $facebook->getSession()) {
printf('<script type="text/javascript">top.location.href="%s";</script>',
$facebook->getLoginUrl(
array('canvas' => 1,
'fbconnect' => 0,
#'req_perms' => 'user_location',
)));
exit();
} else {
try {
$me = $facebook->api('/me');
$first_name = $me['first_name'];
$city = $me['location']['name'];
$female = ($me['gender'] == 'male' ? 0 : 1);
$avatar = 'http://graph.facebook.com/' . $me['id'] . '/picture?type=large';
} catch (FacebookApiException $e) {
exit('Facebook error: ' . $e);
}
}
# print the logo, the flash game and 3 links
?>
此外,我不确定我的PHP脚本是否应打印
Also I'm not sure if my PHP-script is supposed to print
<html>
<body>
.....
</body>
</html>
?目前我只打印身体里面的东西。
? Currently I only print what's inside the body.
我想知道替换 top.location.href = .... 在我的代码中由PHP的标题('位置:....'); ?
And I wonder if it is a good idea to replace top.location.href=.... in my code by PHP's header('Location: ....');?
推荐答案
如果您打算使用Asynchronous方法,建议您在其中放入尽可能多的FB代码。类似下面的内容应该有效:
If you are going to use the Asynchronous method, it's recommended that you put as much of FB code within it. Something like the below should work:
<html>
<head>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: 'your app id', status: true, cookie: true,
xfbml: true});
FB.Canvas.setSize();
};
function sizeChangeCallback() {
FB.Canvas.setSize();
}
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
</body>
</html>
现在你将调用 sizeChangeCallback()
每当你对布局进行更改时都会运行(单击新选项卡,加载Ajax内容等)。
Now you will call the sizeChangeCallback()
function whenever you make a change to the layout (clicking new tab, loading Ajax content...etc).
这篇关于Facebook iFrame应用程序 - 摆脱垂直滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!