尝试获取用户的付款交易时出现意外错误

时间:2013-07-30 13:17:17

标签: facebook facebook-graph-api facebook-php-sdk

在获取用户的付款交易时,我总是会收到错误。

{
  "error": {
    "message": "An unexpected error has occurred. Please retry your request later.", 
    "type": "OAuthException", 
    "code": 2
  }
}

我尝试了几种方法:

// approach 1
$response = $app['facebook']->api('/'.$app['user']['fbUserID'].'/payment_transactions', 'GET', [
    //'request_id' => $order['requestID'],
    'access_token' => $app['fb.app_id'].'|'.$app['fb.app_secret']
]);

// approach 2
$url = 'https://graph.facebook.com/'.$app['user']['fbUserID'].'/payment_transactions?fields=id&access_token='.$app['fb.app_id'].'|'.$app['fb.app_secret'];

$ch = curl_init();
$options = [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_TIMEOUT => 60,
    CURLOPT_HTTPHEADER => array('Expect:'),
    CURLOPT_CAINFO => DIR.'/vendor/facebook/php-sdk/src/fb_ca_chain_bundle.crt'
];
curl_setopt_array($ch, $options);

$result = curl_exec($ch);

curl_close($ch);

// approach 3
// like 2 but with a fresh access token
$appAccessToken = explode('=', file_get_contents('https://graph.facebook.com/oauth/access_token?client_id='.$app['fb.app_id'].'&client_secret='.$app['fb.app_secret'].'&grant_type=client_credentials'))[1];

即使在Graph API Explorer中,我也会遇到此错误。只有我使用命令行才有效:

$ curl 'https://graph.facebook.com/........./payment_transactions?access_token=.......|.........'

用户是测试用户,也是支付测试人员并进行了成功的测试购买。本地货币支付重大变化被禁用。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

您需要使用应用访问令牌从该端点进行GET。有关详细信息,请参阅https://developers.facebook.com/docs/graph-api/reference/user#payment_transactions