2013-07-14 37 views
2

我正在實施Facebook的新的本地貨幣付款的畫布應用程序和一切工作正常,除了驗證付款與服務器端Facebook圖形調用使用PHP捲曲。本地貨幣付款驗證失敗使用curl php

我不斷收到以下消息:

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

PHP代碼:在瀏覽器中粘貼時這樣payment_id和的access_token正確

$url = 'https://graph.facebook.com/'.$payment_id.'/?access_token='.$access_token; 
$data = get_url($url); 

function get_url($url) 
{ 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 5); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    $tmp = curl_exec($ch); 
    curl_close($ch); 
    return $tmp; 
} 

圖表鏈接單獨工作正常,但它不適用於PHP curl。

儘管使用相同的捲曲功能,但其他圖形調用仍能正常工作。

有沒有人在這裏成功實現了與服務器驗證的本地貨幣支付?

有什麼建議嗎?

謝謝。

+1

什麼叫是你的代碼實際上做了Facebook的服務器嗎?你確定你的代碼中需要Facebook的SDK將在同一網址是什麼?是訪問令牌和支付ID都正確傳遞? – Igy

+1

我按照步驟5a所述閱讀付款信息:http://developers.facebook.com/docs/tutorials/canvas-games/payments/#step5a,並且我檢查了粘貼完整圖表時相同的訪問令牌和付款ID的工作情況鏈接在瀏覽器中 –

+1

您是否在瀏覽器中嘗試了與您的FB會話相同的網址?因爲對於我而言,網址只在FB打開會話時起作用,如果您關閉會話,則網址有時只會起作用 – jenaiz

回答

0

我能夠得到付款ID返回ID與他下面的代碼:

注:購買測試不會從API請求返回。 「我需要 在文檔中對此進行驗證」。

錯誤錯誤:即使使用訪問令牌完全訪問應用程序,只有ID正在返回,並且API限制了其餘信息,在我的情況下。


<?php 
function GetCH($url){ 
$ch=null; 
if(!$ch){ 
$ch = curl_init(); 
} 
curl_setopt($ch, CURLOPT_URL, "".$url.""); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_FORBID_REUSE, true); 
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); 
curl_setopt($ch, CURLOPT_TIMEOUT, 20); 
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

$return=curl_exec($ch); 
if(!curl_errno($ch)){ 
return $return; 
}else{ 
$fb_fail=curl_error($ch); 
return $fb_fail; 
} 
curl_close($ch); 
unset($ch); 
}; 
$payment_id = '901177xxxxxxxxxxx?fields=id,amount,application,created_time,from,status,updated_time,items'; // notice the request for more than just the id using expansion. 
$access_token = '135669679827333|xxxxxxxxxxxxxxx'; // app access token. 
$url = 'https://graph.facebook.com/'.$payment_id.'&access_token='.$access_token; 
$returned=GetCH($url); 
$locs=json_decode($returned, true); 
echo '<pre>'; 
print_r($locs); 
echo '</pre>'; 
?> 

佔位的裁判錯誤報告。

+0

謝謝Shawn。當添加我的payment_id和令牌時,我得到以下異常:'(#100)Unknown fields:amount,from,status,updated_time'刪除這些字段並使用全部或部分這些字段= id,應用程序,動作,refundable_amount,項目,國家,created_time,fraud_status,payout_foreign_exchange_rate,測試'完整的圖形鏈接在瀏覽器中正常顯示正確的結果,但是代碼和我的id和令牌的結果仍然是'發生了意外錯誤。請稍後重試您的請求。我正在使用測試付款的payment_id。你認爲這可能是一個問題嗎? –

+0

我進入我的個人資料,並從我自己的收據中得到了身份證。 –

+0

您是否嘗試過使用我發佈的cURL功能? –

0

我有同樣的問題。這不是關於如何將cUrl請求發送到圖表。 這是因爲當您沒有facebook會話時,API不響應。

這就是爲什麼相同的鏈接不能在cURL中工作,而是在瀏覽器中工作(帶有活動的Facebook會話)。

現在,可以有一個解決方案來做到這一點,但我不會依賴於此。 1)通過cUrl登錄Facebook賬戶並將會話保存在文件中。 2)使用該文件進行會話並因此發出所需的cURL請求。

所以,我也有點卡住了。任何人發現更好的溶劑?

0

我發現的bug報告如下:https://developers.facebook.com/bugs/283875851753617

下面是誰將會停留在這個crazyness獲取代碼。 (注意:不可靠,因爲隨機它不會返回它應該返回的內容,而是返回「出現意外錯誤」,請稍後再重試您的請求。「)

 $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/' . $payment_id . '?access_token=YES_APP_TOKEN_TOKEN'); 
     curl_setopt($ch, CURLOPT_COOKIE, 'c_user=APP_ID'); //not reliable, because not always working. 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_FORBID_REUSE, true); 
     curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); 
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 20); 
     curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
     $result = curl_exec($ch);