Facebook Credits实施有什么问题

时间:2012-03-08 12:52:55

标签: php facebook facebook-graph-api

我正在关注official tutorial以实现FB点数,但它不起作用。

我已添加警告语句以确保代码正在执行,从警报消息中,我确信没有js错误并且正在调用FB.ui。我在回调函数中也有警报消息但没有收到响应。

自从5个小时后我才知道代码中出了什么问题。有人可以帮助我。

该应用的其他信息:

  • Canvas app
  • 未发布(启用沙箱模式)
  • 未注册公司。 FB说我以后可以这样做,所以我刚刚设定了这个国家。我没有注册,因为我需要得出我需要提供哪些银行账户详细信息的结论,因为FB不允许更改它(从界面)

Tool tip says, I can do it later as it is only mandatory for payments

这是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>

如果您发现提醒来电,我会按顺序收到提示信息

  1. 'in placeOrder()'
  2. '创建obj'
  3. '调用FB.ui'
  4. 回调函数中也有警告消息,但它们没有被调用

    为了确保fb正确输入,我实现了Feed post功能并从“postFeedback”的点击事件中调用

    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.');
                    }
                  }
                );
    }
    

    这样可以正常工作并在我的墙上发布Feed

    我还使用https://developers.facebook.com/docs/authentication/signed_request/

    中给出的示例实现了callback.php

    是的,我已正确配置了应用设置

    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, '-_', '+/'));
    }
    
    ?>
    

    我在这个文件中有一些额外的代码来转储跟踪请求的整个请求

1 个答案:

答案 0 :(得分:1)

我在你的某个频道网址中看到'localhost',但是如果你也使用localhost作为你的信用回调网址,那么Facebook就无法覆盖它(因此,没有办法获得这些信用点为了继续)