Facebook iFrame 应用程序 - 如何使用 PHP SDK 获取 Preload FQL 结果?
几年来,我有一个 FBML 应用程序(一个小型 Flash 游戏),我现在正在尝试转换为 iFrame 应用程序。不幸的是,目前还没有太多关于 Facebook iFrame 应用程序的文档。
对于我的游戏,我需要用户的名字、图片、性别和城市。
在我的旧版本中,我有这个预加载 FQL(由 PHP 脚本创建一次):
$fql = array('info' => array('pattern' => 'facebook',
'query' => 'SELECT first_name, sex, pic_big, current_location
FROM user WHERE uid={*user*}'));
$fb->api_client->admin_setAppProperties(
array('preload_fql' => json_encode($fql)));
非常简单:
<?php
require_once('facebook.php');
define('FB_API_ID', 'XXX');
define('FB_AUTH_SECRET', 'YYY');
$fb = new Facebook(FB_API_ID, FB_AUTH_SECRET);
$viewer_id = $fb->require_login();
$data = json_decode($fb->fb_params['info'], true);
$first_name = $data[0][0];
$last_name = $data[0][2];
$female = ($data[0][3] != 'male');
$avatar = $data[0][3];
$city = $data[0][4]['city'];
# and then I'd just construct flashvars attribute
# for the <fb:swf ...> tag and print it
?>
然后我的 FBML 应用程序脚本 >如何通过 iFrame 应用获取 Preload FQL 结果?
根据较早的 Facebook 博客条目预加载 FQL 应该可由 iFrame 应用访问。
谢谢你! 亚历克斯
since few years I have an FBML app (a small Flash game) which I'm now trying to convert to an iFrame app. Unfortunately there aren't many docs for Facebook iFrame apps yet.
For my game I need the user's first name, picture, gender and the city.
In my old version I had this preload FQL (created once by a PHP script):
$fql = array('info' => array('pattern' => 'facebook',
'query' => 'SELECT first_name, sex, pic_big, current_location
FROM user WHERE uid={*user*}'));
$fb->api_client->admin_setAppProperties(
array('preload_fql' => json_encode($fql)));
and then my FBML app script had been as simple as:
<?php
require_once('facebook.php');
define('FB_API_ID', 'XXX');
define('FB_AUTH_SECRET', 'YYY');
$fb = new Facebook(FB_API_ID, FB_AUTH_SECRET);
$viewer_id = $fb->require_login();
$data = json_decode($fb->fb_params['info'], true);
$first_name = $data[0][0];
$last_name = $data[0][2];
$female = ($data[0][3] != 'male');
$avatar = $data[0][3];
$city = $data[0][4]['city'];
# and then I'd just construct flashvars attribute
# for the <fb:swf ...> tag and print it
?>
Does anybody please have hints on how to recreate the same script for the iFrame version - i.e. how can I fetch the result of Preload FQL by my iFrame app?
According to an older Facebook blog entry Preload FQL should be accessible by the iFrame apps.
Thank you!
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
经过长时间搜索后,我自己的答案是 Preload FQL 结果不会发送到 iframe Facebook 应用程序。
这就是为什么 Facebook 性能文档 说:
“预加载 FQL 查询和多重查询。
本节适用FBML 画布页面,但不是网站或 IFrame 画布页面。”
My own answer after long searching is that Preload FQL results aren't sent to iframe Facebook apps.
That is why Facebook performance doc says:
"Preload FQL Query and Multiquery.
This section applies to FBML canvas pages, but not to websites or IFrame canvas pages."
正如 Facebook 对于预加载 FQL 所说
,“Facebook 会将这些 FQL 查询的结果作为 JSON 编码的 POST 参数发送到您的 Canvas URL”
print_r 您的 $_POST 并查看哪个变量是“json 编码结果”。您可以使用 json_decode 将 json 转换为 php 对象
JSON 如下所示:
{"var":"val","var":"val"}
另外,Facebook 已经有很棒的 iframe 文档。那么您可能错过了这些很棒的文档:
Facebook 文档主页
http://developers.facebook.com/docs/
身份验证
http://developers.facebook.com/docs/authentication/
签名请求
< a href="http://developers.facebook.com/docs/authentication/signed_request/" rel="nofollow">http://developers.facebook.com/docs/authentication/signed_request/
iFrame 画布应用
http://developers.facebook.com/docs/guides/canvas/
PHP SDK
https://github.com/facebook/php-sdk
图形 API
http://developers.facebook.com/docs/reference/api/
As Facebook said for Preload FQL
"Facebook will send the result of these FQL queries as JSON-encoded POST parameters to your Canvas URL"
print_r your $_POST and see which variable is the "json-encoded results". You convert json into php object using json_decode
JSON looks like this:
{"var":"val","var":"val"}
Also, Facebook already has great docs for iframes. Then you might have missed these great docs:
Facebook Docs Home
http://developers.facebook.com/docs/
Authentication
http://developers.facebook.com/docs/authentication/
Signed Request
http://developers.facebook.com/docs/authentication/signed_request/
iFrame Canvas Apps
http://developers.facebook.com/docs/guides/canvas/
PHP SDK
https://github.com/facebook/php-sdk
Graph API
http://developers.facebook.com/docs/reference/api/
您无需调用任何 FQL 即可获取所获取的信息。对于 iFrame,您只需执行以下步骤
下载 graph api 的 PHP SDK https://github .com/facebook/php-sdk/
创建对象并从用户授权应用程序
”;
}
// 创建我们的应用程序实例。
$facebook = 新 Facebook(数组(
'应用程序ID' => $fbconfig['appid'],
'秘密' => $fbconfig['秘密'],
'cookie'=>真的,
));
// 用户位置扩展权限允许您获取用户的当前位置
$loginparams = array('canvas' => 1,'fbconnect' => 0,'req_perms' => 'user_location');
$loginUrl = $facebook->getLoginUrl($loginparams);
// 我们可能有也可能没有基于 $_GET 或 $_COOKIE 的会话的数据。
// 如果我们在这里得到一个会话,这意味着我们找到了一个正确签名的会话
// 应用程序秘密只有 Facebook 和应用程序知道。我们不知道
// 如果在我们使用会话进行 API 调用之前它仍然有效。一次会议
// 如果已经过期,则可能会变得无效(不应该获取
// 在这种情况下会话返回)或者如果用户退出 Facebook。
$session = $facebook->getSession();
$fbme = null;
// 基于会话的图形 API 调用。
如果($会话){
尝试 {
$uid = $facebook->getUser();
$fbme = $facebook->api('/me');
} catch (FacebookApiException $e) {
d($e);
}
}
函数 d($d){
回显“<前>”;
打印_r($d);
回显“”;
}
//可以找到这个数组中的所有数据。
print_r($fbme);
有关更多详细信息,您可以按照本教程 http:// thinkdiff.net/facebook/php-sdk-graph-api-base-facebook-connect-tutorial/
希望它对您有用
You don't need to call any FQL for the information you are getting. For iFrame you just need to do following steps
Download the PHP SDK of graph api https://github.com/facebook/php-sdk/
Create the object and authorize the app from user
// You can found all the data in this array.
print_r($fbme);
For more detail you can follow this tutorial http://thinkdiff.net/facebook/php-sdk-graph-api-base-facebook-connect-tutorial/
Hope it works for you