php - What is wrong in Facebook Credits implementation -
i following official tutorial implement fb credits not working.
i have added alert statements make sure code executing, alert messages, sure there no js errors , fb.ui being called. have alert messages in callback function no response received.
i breaking head since 5 hours figure out wrong in code. can 1 please me.
additional info on app:
- canvas app
- not published (sandbox mode enabled)
- not registered company. fb says can later have set country. have not registered because need come conclusion on bank account details need give because fb wont allow change (from interface)
here 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 allow server access 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>
if notice alert calls, getting alert messages in order
- 'in placeorder()'
- 'creating obj'
- 'calling fb.ui'
there alert messages in callback function not being called
to make sure fb inited have implemented feed post function , called "postfeedback"'s click event
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 simple, consistent interface applications interface users.' }, function(response) { if (response && response.post_id) { alert('post published.'); } else { alert('post not published.'); } } ); }
this working fine , posting feed on wall
i have implemented callback.php using example given in https://developers.facebook.com/docs/authentication/signed_request/
and yes, have configured app settings properly
callback.php
<?php include_once 'config.php'; mysql_connect('localhost','root',''); mysql_select_db("precious_world"); //var_dump($_request); //dump request db $request = join(':', $_request); $request = mysql_real_escape_string($request); $query = "insert 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 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, '-_', '+/')); } ?>
i have code in file dump entire request trace request
i see 'localhost' in there in 1 of channel urls, if you're using localhost credits callback url there's no way facebook able reach (and thus, there's no way credits order proceed)
Comments
Post a Comment