欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Facebook Credit

程序员文章站 2022-05-03 15:51:47
...

最近在整合facebook credit,资源如下:

 

官方API地址:http://developers.facebook.com/docs/creditsapi/

官方的demo下载:https://github.com/facebook/credits-api-sample

测试账号:http://www.facebook.com/notes/mukesh-chapagain/sample-valid-credit-card-numbers-for-testing/10150112451188338

一个sample:http://apps.facebook.com/ratemeshareme/starrater/D/

流程详解:http://developers.facebook.com/blog/post/489

 

步骤:

1.新建应用和部署服务器,注意,测试服务器必须在公网 并且一定要保证facebook后台能够正确访问callback.php这个文件 ,localhost测试一直会报错:

The application you are using is not responding.

2.在facebook app设置里面,http://www.facebook.com/developers

Edit Settings->Advanced->set "OAuth 2.0 for Canvas" to "Enabled"

Credits Tab, register your company && set your Credits Callback URL

 

3.get credit balance

  这个问题其实我弄了好久,现在回想起来其实并不复杂,只是走了很多弯路,总结如下:

a.complete Credits Special Incentives Support,link

  这个需要facebook审核,成功之后faceboo会给你发送邮件,接受邮件的地址就是你申请这个support的facebook账号的邮箱,这个要切记。

 邮件的大概内容会是这样的:

In re-assessing your game's eligibility, we've enabled the requested app IDs for special incentives features testing: http://www.facebook.com/help/?faq=19840. 
 
Please notify us when your game is ready to launch Facebook Credits as your premium currency so that we can assess for distribution opportunities.
 

b.申请成功之后然后就可以写代码测试了

 

define('APP_ID', '');
define('API_KEY', '');
define('SECRET', '');
require_once("FacebookManager.php");
$facebook  = new FacebookManager(array(
      'appId'  =>  APP_ID,
      'secret' =>  SECRET,
      'cookie' =>  true
));
$user = $facebook->require_login("http://apps.facebook.com/xxx/","","email,publish_stream,user_birthday");

  $session = $facebook->getSession();

  $facebook_id = $facebook->getUser();

  $access_token = APP_ID.'|'.SECRET;  //注意此处的access_token,其实是app_token,不同于$session['access_token']

  $obj = json_decode( 
         file_get_contents('https://api.facebook.com/method/users.getStandardinfo'.
                           '?uids=' . $facebook_id . 
                           '&fields=credit_balance&access_token=' . $access_token . 
                           '&format=json'));

  echo '<pre>';
  print_r($obj);

 

c.如果出现:

The underlying FQL query made by this API call has encountered the following error: credit_balance is not a member of the user table

   那是因为第一步没有通过,重新申请。

   如果出现:

The method you are calling must be called with an app secret signed session

    那就是混淆了access_token,在这里我们必须要使用

$access_token = APP_ID.'|'.SECRET;

    或者:

$url = 'https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id='.$APP_ID.'&client_secret='.$FB_API_SECRET;
$access_token = @file_get_contents($url);

 

d.使用api调用来获取balance会报错

$credit_balance = $facebook->api(array('method'  => 'users.getStandardInfo','uids' => $facebook_id , 'fields' => 'credit_balance'));

   这个暂时还没有找到解决办法