我跟随official tutorial实施FB积分,但它不起作用。Facebook积分实施有什么问题
我加入警报报表,以确保代码执行,从警报消息,我相信没有JS错误,FB.ui被调用。我在回调函数中也有警报消息,但没有收到响应。
我打破我的头,因为5小时弄清楚什么是错的代码。有人可以帮帮我吗。
上的应用程序附加信息:
- 画布应用程序(启用沙盒模式)
- 未公布
- 没有注册公司。 FB说我以后可以做,所以我刚刚设置了国家。我还没有注册,因为我需要到哪个银行帐户资料,我需要放弃,因为FB不会允许改变它(从界面)的结论
这里是buy.php
<?php
include_once '/Config.php';
include_once '/fb-sdk/facebook.php';
?>
<html>
<head>
<title>My Facebook Credits Page</title>
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : '<?php echo Config::$appId?>',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
channelUrl : 'http://localhost/buy.php', // channel.html file
oauth : true // enable OAuth 2.0
});
var callback = function(data) {
if (data['order_id']) {
alert('called back');
return true;
} else {
//handle errors here
alert('some error');
return false;
}
};
function placeOrder(){
alert('in placeOrder()');
var order_info = 'myorderinfo';
alert('creating obj');
var obj = {
method: 'pay',
order_info: order_info,
action: 'buy_item',
dev_purchase_params: {'oscif': true}
};
alert('calling ui');
FB.ui(obj, callback);
}
</script>
<input type="button" value="post" onclick="postFeed()" />
<input type="button" value="Buy" onclick="placeOrder()" />
</body>
</html>
如果您发现警报电话,我在为了获得警报消息
-
'在placeOrder()'
- '创建OBJ'
- '调用FB.ui'
有回调函数太警报消息,但他们没有被称为
要确保
function postFeed(){
alert('in postFeed()');
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
}
这是工作的罚款和宝FB是inited妥善我已经实现了新闻发布功能,并呼吁从“postFeedback” click事件在我的墙上
我已经使用在https://developers.facebook.com/docs/authentication/signed_request/
给出的例子还实施了callback.php和Sting饲料是的,我已经配置了应用程序的设置适当
callback.php
<?php
include_once 'Config.php';
mysql_connect('localhost','root','');
mysql_select_db("precious_world");
//var_dump($_REQUEST);
//dump the request into the db
$request = join(':', $_REQUEST);
$request = mysql_real_escape_string($request);
$query = "insert into fbcredits_callback(data)values('$request')";
$result = mysql_query($query);
$fb_signed_req = $_REQUEST['signed_request'];
echo parse_signed_request($signed_request, Config::$appSecret);
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
?>
我在这个文件中有一些额外的代码来转储整个请求以跟踪请求
aaaaaw所以我就在主持人的主持下。为此。我会检查 – 2012-03-08 17:05:40
所以为了检查订单的事情,我不得不提到实时网址?没有别的办法吗? – Volatil3 2012-03-21 10:38:33
不,您可以使用另一个URL,但必须通过Facebook服务器访问。 – Gabriel 2012-06-21 07:32:16