Facebook本地货币支付示例

As Facebook are forcing us to change ways once again, we need to introduce their "local currency" as payment option in our app.

However, I'm finding the documentation hard to understand, and are in desperate need of some example code. If anyone knows of some sample code, it would be greatly appreciated.

I think this error occurs if you are the developer/owner of the app, try a different account

I have only just worked this out myself and have not yet completed the callback, I will edit my answer then. Hope this is useful to someone. First make a graph object

<head prefix=
"og: http://ogp.me/ns# 
fb: http://ogp.me/ns/fb# 
product: http://ogp.me/ns/product#">
<meta property="og:type"                   content="og:product" />
<meta property="og:title"                  content="Friend Smash Coin" />
<meta property="og:plural_title"           content="Friend Smash Coins" />
<meta property="og:image"                  content="http://www.friendsmash.com/images/coin_600.png" />
<meta property="og:description"            content="Friend Smash Coins to purchase upgrades and items!" />
<meta property="og:url"                    content="https://www.yourdomain.com/test.html" />
<meta property="product:price:amount"      content="0.30"/>
<meta property="product:price:currency"    content="USD"/>
<meta property="product:price:amount"      content="0.20"/>
<meta property="product:price:currency"    content="GBP"/>
</head>

Save this as an html file and upload it to your server, lets say yourdomain.com/test.html

Visit this page https://developers.facebook.com/tools/debug and enter yournew url here (yourdomain.com/test.html)

change the product url below to your domain (yourdomain.com/test.html)

<h2>Purchase a product:</h2>
<button id="pay">Buy Product</button>
<div class="returndata" id="output"></div>


<div id="fb-root"></div>
<script type="text/javascript">
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'APPID',
      status     : true,
      cookie     : true,
      xfbml      : true
    });

    function buy() {
      var obj = {
        method: 'pay',
        action: 'purchaseitem',
        product: 'http://yourdomain.com/test.html'
      };

      FB.ui(obj, function(data) {
          console.log(data);
        });
    }

    document.getElementById('pay').onclick = function() {buy()};
  };

  // Load the SDK Asynchronously
  (function(d){
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
    if (d.getElementById(id)) { return; }
    js = d.createElement('script'); js.id = id; js.async = true;
    js.src = "//connect.facebook.net/en_US/all.js";
    ref.parentNode.insertBefore(js, ref);
  }(document));
</script>