Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7608833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:01:17+00:00 2026-05-31T01:01:17+00:00

I am following the official tutorial to implement the FB credits but its not

  • 0

I am following the official tutorial to implement the FB credits but its not working.

I have added alert statements to make sure the code is executing, from the alert messages, I am sure that there are no js errors and FB.ui is being called. I have alert messages in the callback function also but no response received.

I am breaking my head since 5 hours to figure out what is wrong in the code. Can some one please help me.

Additional info on the app:

  • Canvas app
  • Not published (sandbox mode enabled)
  • Not registered the company. FB says I can do it later so I have just set the country. I have not registered because I need to come to a conclusion on which bank account details I need to give because FB wont allow to change it (from the interface)

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

Here is the 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>

If you notice the alert calls, I am getting alert messages in the order

  1. ‘in placeOrder()’
  2. ‘creating obj’
  3. ‘calling FB.ui’

there are alert messages in the callback function too but they are not being called

To make sure the fb is inited properly I have implemented feed post function and called from the “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 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.');
                }
              }
            );
}

This is working fine and posting feed on my wall

I have also implemented the callback.php using the example given in the https://developers.facebook.com/docs/authentication/signed_request/

And yes, I have configured the app settings properly

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

?>

I have some extra code in this file to dump the entire request to trace the request

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:01:18+00:00Added an answer on May 31, 2026 at 1:01 am

    I see ‘localhost’ in there in one of your channel URLs, but if you’re also using localhost as your credits callback URL there’s no way Facebook will be able to reach it (and thus, there’s no way for the credits order to proceed)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working with web2py following its official web2py book and got to
Hello Entity Frameworks Gurus!! I've been following the official tutorial and have started a
The official documentation states the following: . But I have noticed that there are
following official freebase facebook app tutorial , in Step 4 it mentions the Acre
I am following the official Django tutorial. I'm stuck in Part 2 . I
I was following the ListView official tutorial - [url]http://developer.android.com/resources/tutorials/views/hello-listview.html[/url], because I get the entries
I'm following the Official tutorial for creating a administration area. I did the first
The official method Environment.getExternalStorageDirectory() seems to be not working on Samsung devices... It return
I followed the official Authlogic tutorial but something came up. I successfully created a
From an official Eclipse plugin development tutorial, I copied the following code to define

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.